Forum Moderators: open
This works fine and it will display the page on the fly with the spans functioning, but the problem is that I need to somehow output all of the source html with the actual span tags included.
Is there any way with DOM scripting that I can access/output the full source with the changes were made dynamically (and don't show on the actual html source)?
I need to get it into a variable or in some other way, but I don't know if this is even possible...
<HTML>
<HEAD>
<STYLE>
.js { color: white; background-color: orange; font-weight: bold; }
</STYLE>
<SCRIPT>
function spanAllTextNodes (styleClass, element) {
if (!element)
element = document.body;
for (var c = 0; c < element.childNodes.length; c++)
if (element.childNodes[c].nodeType == 3) {
var span = document.createElement('SPAN');
span.className = styleClass;
var textNode = element.replaceChild(span, element.childNodes[c]);
span.appendChild(textNode);
}
else
spanAllTextNodes(styleClass, element.childNodes[c]);
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="spanAllTextNodes('js');">
<A HREF="here">
Some Text
</A>
<P>
More Text
</P>
<TABLE>
<TR>
<TD>
More Text
</TD>
</TR>
</TABLE>
</BODY>
</HTML>