I have a string such as
<html><body><div id="message">Hello World!</div></body></html>
and I would like to get the content of the #message element without parsing the HTML myself.
I thought maybe I could create a document object from a string in Gecko (this is for a Firefox add on) but I don't see any simple way.
I noticed that there is a createDocument method, but that doesn't take a string. I'd have to strip the <html>
portion from the text, and then again I'm starting to assume stuff.
Anyone have any ideas? Thanks.
EDIT: This seems to work for me:
doc = document.implementation.createDocument( "http://www.w3.org/1999/xhtml", "html", null );
doc.firstChild.innerHTML = '<html><body><div id="message">Hello World!</div></body></html>';
node = doc.getElementById( "message" );
alert( node.innerHTML );