How to replace part of a string with html tag in jQuery?Say, for example, <div>Who am i</div> should be <div><b>Who</b> am i</div> .
<div>Who am i</div>
<div><b>Who</b> am i</div>
You can use the html callback function and the replace method.
html
replace
$('div').html(function(_, oldHTML){ return oldHTML.replace(/(\w+)/, '<b>$1</b>'); // return oldHTML.replace('Who', '<b>Who</b>'); })
http://jsfiddle.net/3rAMp/
use .html() for jquery
.html()
$("div").html("<b>Who</b> am i")