Get text from character and after using jQuery
I want to get the text from a string after the occurrence of a specific character.
Lets say: texttexttext#abc And I want to get abc
How is this done in jquery? (This might be trivial to somebody, but I have little exp 开发者_C百科in jQuery)
you could do:
var text = 'texttexttext#abc';
var abc = text.substring(text.indexOf('#') +1);
You don't need to use jQuery for this. Simple javascript is fine.
In this case:
var text = 'texttexttext#abc';
var textAfterHash = text.split('#')[1];
or
var textAfterHash = text.substring(text.indexOf('#') + 1);
JSFiddle Example of both
Contrary to popular belief, jQuery isn't needed in every situation ;)
Example:
var x = 'texttexttext#abc';
var y = x.substring(x.indexOf('#') + 1);
alert(y); //abc
精彩评论