开发者

Jquery to stylize only certain word from para

开发者 https://www.devze.com 2023-01-09 13:33 出处:网络
I want to stylize only certain word from my dynamic div say, <div id=\"info\">{$info}</div> prints

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; }
0

精彩评论

暂无评论...
验证码 换一张
取 消