Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字列の一部をjQueryのhtmlタグに置き換える方法は? たとえば、 と言う<div>Who am i</div>必要があります<div><b>Who</b> am i</div>。
<div>Who am i</div>
<div><b>Who</b> am i</div>
htmlメソッドのコールバック関数とメソッドを使用できますreplace。
html
replace
$('div').html(function(_, oldHTML){ return oldHTML.replace(/(\w+)/, '<b>$1</b>'); // return oldHTML.replace('Who', '<b>Who</b>'); })
http://jsfiddle.net/3rAMP/
.html()jqueryの使用
.html()
$("div").html("<b>Who</b> am i")