Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of a character

Tags:

jquery

colors

I have the following HTML code:

<p>
<label>* Name</label>
</p>
<p>
<label>* Last Name</label>
</p>
<p>
<label>Mascot Name</label>
</p>

Is it possible to change the color only to the character * with jQuery? I tried with the function find() but I repeat all the characters on the label.

like image 425
csotelo Avatar asked Jan 16 '12 14:01

csotelo


1 Answers

If you insist on a scripted solution:

$("p > label:contains('*')").each(function () {
    $(this).html($(this).html().replace("*", "<span class='red'>*</span>"));
});

Demo.

like image 68
karim79 Avatar answered Sep 17 '22 08:09

karim79