Hi.
I currently am trying to add tags around certain words in a webpage. This webpage can have many different id's, classes, and names, so it's important that if I'm trying to put a span around "foo" I do the following:
<p class='foo'>blah blah blah foo blah blah blah </p>
changes into
<p class='foo'>blah blah blah <span class='bar'> foo </span> blah blah blah </p>
and not
<p class='<span class='bar'> foo </span>'>blah blah blah <span class='bar'> foo </span> blah blah blah </p>
I'm investigating parsing the website out using the following code:
var obj = $(this.innerHTML); //in my selector which selects the part of the website I want to apply the span to
I'm able to browse this data structure in firebug, but modifying it (or searching it) is proving to be more difficult.
If I look at obj[1], the innerHTML property looks like this:
<h4 id="3423df" class="pzCMD">blah blah foo blah </h4>
I have no idea how to modify this element (if possible) or add new nodes to it. I can extract the "text" by looking at the textContent
obj[1].textContent = blah blah foo blah
but I'm unsure how I would go about changing the html code of this element to
<h4 id="3423df" class="pzCMD">blah blah <span class='bar' foo <span> blah </h4>
Thanks for any help, sorry for the long drawn out explanation.