dom - Insert HTML into text node with JavaScript -


i've got little text node:

var node 

and want wrap span around every occurrence of "lol".

node.nodevalue = node.nodevalue.replace(/lol/, "<span>lol</span>") 

it prints out "<span>lol<span>" when want "lol" span element.

you may need node parent node, way can use innerhtml:

node.innerhtml=node.childnodes[0].nodevalue.replace(/lol/, "<span>lol</span>"); 

here node.childnodes[0] refers actual text node, , node containing element.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -