JQuery Remove string from string?

If you just want to remove "username1" you can use a simple replace.

If you just want to remove "username1" you can use a simple replace. Name. Replace("username1,", "") or you could use split like you mentioned.

Var name = "username1, username2 and username3 like this post. ". Split(",")1; $("h1").

Text(name); jsfiddle example.

Pretty sure you just want the plain old replace function. Use like this: myString. Replace('username1',''); I suppose if you want to remove the trailing comma do this instead: myString.

Replace('username1,',''); edit: here is your site specific code: jQuery("#post_like_list-510").text(). Replace(...).

I tried that and got the error(firebug) jQuery("#post_like_list-510"). Replace is not a function – Carl markham Feb 23 '11 at 18:09 @carl, thats because the myString variable is just a string, not a jquery object. So do jQuery("#post_like_list-510").text().

Replace(...) – nathan gonzalez Feb 23 '11 at 18:11 you probably want jQuery('#post_like_list-510').val(). Replace(...) – matei Feb 23 '11 at 18:11 @Carl markham: The function is a string function, not a jQuery function. – Felix Kling Feb 23 '11 at 18:11 @matei, val() won't return the expected result on an object like a div or span if I recall correctly.

– nathan gonzalez Feb 23 '11 at 18:12.

I assume that the text "username1" is just a placeholder for what will eventually be an actual username. Assuming that, If the username is not allowed to have spaces, then just search for everything before the first space or comma (thus finding both "u1 likes this" and "u1, u2, and u3 like this"). If it is allowed to have a space, it would probably be easier to wrap each username in it's own span tag server-side, before sending it to the client, and then just working with the span tags.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions