Part of my code I get the OuterHTML propery
"<LI onclick="TabClicked(this, 'SearchName', 'TabGroup1');">Name "
so I can do stuff involing parsing it.
There is no OuterHTML property in javascript on firefox though and I can't find an alternative way to get this string. Ideas?
Using jQuery With jQuery, you can access the outerHTML attribute of HTML using the $(selector). prop() or $(selector). attr() method.
The outerHTML attribute of the Element DOM interface gets the serialized HTML fragment describing the element including its descendants. It can also be set to replace the element with nodes parsed from the given string.
The outerHTML is the HTML of an element including the element itself. Use the outerHTML when you want to completely replace an element and its contents. Use innerHTML when you only want to replace the contents of the element.
Editing HTML You can edit the HTML — tags, attributes, and content — directly in the HTML pane: double-click the text you want to edit, change it, and press Enter to see the changes reflected immediately. You can add any HTML in here: changing the element's tag, changing existing elements, or adding new ones.
Here's the function we use in pure.js:
function outerHTML(node){ return node.outerHTML || new XMLSerializer().serializeToString(node); }
To use it the DOM way:
outerHTML(document.getElementById('theNode'));
And it works cross browsers
EDIT: WARNING! There is a trouble with XMLSerializer, it generates an XML(XHTML) string.
Which means you can end up with a tags like <div class="team" />
instead of<div class="team"></div>
Some browsers do not like it. I had some pain with Firefox 3.5 recently.
So for our pure.js
lib we came back to the old and safe way:
function outerHTML(node){ // if IE, Chrome take the internal method otherwise build one return node.outerHTML || ( function(n){ var div = document.createElement('div'), h; div.appendChild( n.cloneNode(true) ); h = div.innerHTML; div = null; return h; })(node); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With