Posted By: Anonymous
$("#topNav" + $("#breadCrumb2nd").text().replace(" ", "")).addClass("current");
This is a snippet from my code. I want to add a class to an ID after getting another ID’s text property. The problem with this, is the ID holding the text I need, contains gaps between the letters.
I would like the white spaces removed. I have tried
REPLACE() but this only partially works. The
REPLACE() only removes the 1st space.
You have to tell replace() to repeat the regex:
If you want to match all whitespace, and not just the literal space character, use
You can also use
.replaceAll, it must be global, so you just end up with extra typing: