开发者

How to put HTML in jQuery .text()

开发者 https://www.devze.com 2023-01-08 17:38 出处:网络
I couldn\'t find this anywhere, partly because its keywords are pretty common. $(\'.pause_button\').text(\'<img src=\"../imgs/icons/control_pause_blue.png\" alt=\"Resume\"开发者_开发技巧 /> Res

I couldn't find this anywhere, partly because its keywords are pretty common.

$('.pause_button').text('<img src="../imgs/icons/control_pause_blue.png" alt="Resume"开发者_开发技巧 /> Resume');

How can this be printed as HTML and not convert the brackets and apostrophes?


Make use of the .html function avaialble in jQuery, .html().

For example:

$('div.demo-container').html('<p>All new content. <em>You bet!</em></p>');

In your case

$('.pause_button').html('<img src="../imgs/icons/control_pause_blue.png" 
alt="Resume" /> Resume');


.text() actually escapes all HTML specific characters, .html() doesn't.


Use .html()

$('.pause_button').html('<img src="../imgs/icons/control_pause_blue.png" alt="Resume" /> Resume'); 


use .html()

$('.pause_button').html('<img src="../imgs/icons/control_pause_blue.png" alt="Resume" /> Resume');


You should use .html();.


Use .html() instead of .text().

0

精彩评论

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