How to create the DOM element using jquery [duplicate]
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);
精彩评论