In my userscript web browser project, I need to replace only one node text without affecting other HTML elements under the same node parent as text. And I need to replace it with more than one node:
<div id="target"> foo / bar; baz<img src="/image.png"></div>
Need to become:
<div id="target"> <a href="#">foo</a> / <a href="#">bar</a>; <a href="#">baz</a><img src="/image.png"></div>
I know jQuery does not have much support for text nodes. I know that instead of jQuery I could use direct DOM calls. And I know that I can just do something like $('#target').html( my new material + , which I don't want to change ) . Also note that I would like to keep the initial space, this in itself seems complicated.
What I would like to ask the experts here, Is there any idiomatic jQuery way for this?
source share