javascript - jQuery - Replace text with text plus html element -
i have text wish replce using jquery. problem is, text not within it's own element, content dynamic , can not access html markup make things easier.
i can detect , replace text in question, have managed replace new text node, therefore treats html tags text , not markup
demo http://jsfiddle.net/xvtgp/
$('div.mydiv').contents().filter(function () { return this.nodetype == 3 }).each(function () { this.textcontent = this.textcontent.replace('my old text no in own element', '<div class="newclass">my new text</div>'); var mynewnode = this.textcontent; return });
current output text
<div class="newclass">my new text</div>
just replace textnode div using replacewith()
$($('div.mydiv div').get(0).nextsibling).replacewith('<div class="newclass">my new text</div>');
Comments
Post a Comment