Quantcast
Channel: How to get the HTML for a DOM element in javascript - Stack Overflow
Browsing latest articles
Browse All 11 View Live

Answer by pery mimon for How to get the HTML for a DOM element in javascript

old question but for newcomers that come around : document.querySelector('div').outerHTML

View Article



Answer by Pawan Jasoria for How to get the HTML for a DOM element in javascript

var x = $('#container').get(0).outerHTML;

View Article

Answer by Remi for How to get the HTML for a DOM element in javascript

define function outerHTML based on support for element.outerHTML: var temp_container = document.createElement("div"); // empty div not added to DOM if (temp_container.outerHTML){ var outerHTML =...

View Article

Answer by kennebec for How to get the HTML for a DOM element in javascript

If you want a lighter footprint, but a longer script, get the elements innerHTML and only create and clone the empty parent- function getHTML(who,lines){ if(!who || !who.tagName) return ''; var txt,...

View Article

Answer by Jørn Schou-Rode for How to get the HTML for a DOM element in...

Expanding on jldupont's answer, you could create a wrapping element on the fly: var target = document.getElementById('myElement'); var wrap = document.createElement('div');...

View Article


Answer by Nikolas Stephan for How to get the HTML for a DOM element in...

You'll want something like this for it to be cross browser. function OuterHTML(element) { var container = document.createElement("div"); container.appendChild(element.cloneNode(true)); return...

View Article

Answer by Zenon for How to get the HTML for a DOM element in javascript

as outerHTML is IE only, use this function: function getOuterHtml(node) { var parent = node.parentNode; var element = document.createElement(parent.tagName); element.appendChild(node); var html =...

View Article

Answer by Majkel for How to get the HTML for a DOM element in javascript

Use outerHTML: var el = document.getElementById( 'foo' ); alert( el.outerHTML );

View Article


Answer by Jason Leveille for How to get the HTML for a DOM element in javascript

var el = document.getElementById('foo'); el.parentNode.innerHTML;

View Article


Answer by jldupont for How to get the HTML for a DOM element in javascript

First, put on element that wraps the div in question, put an id attribute on the element and then use getElementById on it: once you've got the lement, just do 'e.innerHTML` to retrieve the HTML....

View Article

How to get the HTML for a DOM element in javascript

Imagine I have the following HTML: <div><span><b>This is in bold</b></span></div> I want to get the HTML for the div, including the div itself. Element.innerHTML...

View Article
Browsing latest articles
Browse All 11 View Live




Latest Images