开发者

How to create the DOM element using jquery [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How do I add a DOM element with jQuery?

var re = new RegExp("\\b(" + l + ")\\b")
var sOpen = "<span class='highlight'>";
var sClose = "</span>";
var newhtml = sp.replace(re, sOpen + l + sClose, "gi");
alert(newhtml);
$('.highlight').css('color', 'yellow');

I am getting newHtml value as

I love to work with <span class='highlight'>jquery</span>

I am highlight the highlig开发者_C百科ht class item. jquery but its not hightlighting the text. please can any body tell me is that something I am doing wrong here?

how to create a newhtml as DOm element?

thanks


Even better would be to wrap it with the built-in logic:

$('myelement').wrap('<span/>').parent().addClass('highlight');


You can create an object of it and add it to the DOM:

var newhtml = $(sp.replace(re, sOpen + l + sClose, "gi"));
$(body).append(newhtml); 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜