Get text from character and after using jQuery

I want to get text from a string after a certain character appears.

Let's say: texttexttext # abc And I want to get abc

How is this done in jquery? (This may be trivial to someone, but I have little experience in jQuery)

+7
source share
3 answers

You can do:

var text = 'texttexttext#abc'; var abc = text.substring(text.indexOf('#') +1); 
+12
source

You do not 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 how

+9
source

Contrary to popular belief, jQuery is not required in every situation;)

Example:

 var x = 'texttexttext#abc'; var y = x.substring(x.indexOf('#') + 1); alert(y); //abc 
+4
source

All Articles