I’m a little disappointed JQuery doesn’t have something uber fancy for this. Something that always catches me out is when trying to replace occurrences of a string, it only replaces the first if you use the default “.replace” method.

In order to replace all occurrences, you need to treat your JS to a little RegEx-esk treat.

The “g” modifier is actually all it takes to do this, but obviously, it also open up a world of RegEx to play about with if you want to.

Image Credit: Lorenzoclick