Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- replacing innerHTML in xhtml
- Denis McMahon
July 28, 2008, 8:49 am
rate this thread
A relative has a web page that they want to work with google checkout,
so it has to be xhtml, as the google scripts require xhtml.
However, I wish to replace the text content of an id'd span.
In html 4.01, I could do this with the innerhtml property, but that's
not supported in xhtml.
Any suggestions? I can find examples that show me how to create an
additional textnode and add text to it, but not ones that show me how to
update or replace [the content of] an existing textnode.
Re: replacing innerHTML in xhtml
document.getElementById('spanId').firstChild.nodeValue = 'foo';
However as long as you serve the XHTML document as text/html it should
be no problem at all to use innerHTML, and even if the XHTML is served
as application/xhtml+xml then browsers like Firefox 1.5 and later
support innerHTML for XHTML elements.