according to http://www.w3schools.com/dom/dom%5Fnode.asp, to get the text content of a node, textContent for FF and text for IE, but leaves opera out, is there a cross platform way of getting the inner text content of a node?
A:
The property that's most generic is the nodeValue
property defined here:
http://www.w3schools.com/DOM/prop_document_nodevalue.asp
There is also a property called innerText
that I beleive works in IE6.
The best option is to do some kind of object detection to ensure that the property you want to use, is available in the browser you're currently using.
Alternatively, a Javascript framework such as jQuery, YUI, ExtJS will provide you with methods that are already setup to be cross browser compatable.
Jamie Dixon
2009-11-16 20:46:23
that is not documented in the link, where do you find it?
2009-11-16 20:59:19
doesn't seem like it works
2009-11-16 21:02:43
worth to mention that I am using the DOM to parse a xml, not html
2009-11-16 21:05:49
I've updated my answer after realising that .innerText is most useful for IE. :)
Jamie Dixon
2009-11-16 21:09:30
thanks, I tried this alert(n.childNodes[i].textContent || n.childNodes[i].text); it seems to work for ff,ie, and opera, I am actually using ext-js's DomQuery to parse XML file, but the node that it returns is in WC3 Dom Node. I can't find a utility that would wrap around it
2009-11-16 21:20:14