Johnny Perkins Johnny Perkins - 3 months ago 6
jQuery Question

Total Mystery: simple RegExp code only working on certain pages

I'm stumped. A client asked to change the color of the star at the end of each of the articles on his site.

So easy!!!

This code:

$('.center-col p:contains("✭")').each(function(){
$(this).html(
$(this).html().replace('✭','<span class=\'light-purple\'>✭</span>')
);
});


aught to do it. But no.

It works fine on some pages (e.g. this one and this one) but refuses to work on others (e.g. this one or this one).

All articles are using an identical Wordpress template, and I can't for the life of me find any differences between the articles. I even tried looping through every p tag

$('p').each(function(){
$(this).html(
$(this).html().replace('✭','<span class=\'light-purple\'>✭</span>')
);
});


and still the same result.

Anyone who can solve this mystery is effing man!!

Answer

You're using two different star characters. The character which you're missing is (char code 9733) whereas the character you're searching for is (char code 10029) - they look nearly identical (possibly identical) but they are different Unicode values.

To fix, either use the same star on each page or adjust your regex to include both stars.

Comments