I’m creating few elements with jQuery like this –
var div1 = $('<div />', {text: "Specials of <b>the searched text</b>"}).attr({"class": "spcl-thmb-hdr"});
div1.appendTo(li2); // appending to a <li /> tag
But when they load, they just don’t parse the <b /> tag. and prints something like this –
<div class="spcl-thmb-hdr">Specials of <b>the searched text</b></div>
How do I make it parse the tag in text parameter?
You need to use
htmlinstead oftextfor the string to be seen as HTML, otherwise it will be encoded.The map that you pass into
$can contain attributes, to you can replace theattrcall, also, like this:From the jQuery docs: