Jquery to stylize only certain word from para
I want to stylize only certain word from my dynamic div
say,
<div id="info">{$info}</div> prints
<p>her开发者_开发技巧e you can get info about somnething. if you want more info about something then click here....</p>
I only want stylize the word 'info'
How can I achieve this using jQuery?
Thanks.
Don't use jQuery to add styles to your HTML. You should generate proper HTML and then use CSS styling.
But if you still want to do this:
$("p").html( $("p").text().replace(/word/, "<span class='my-word'>word</span>") );
And in CSS:
.my-word { color: red; }
精彩评论