Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

jquery - Change color of a character

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you insist on a scripted solution:

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

Demo.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...