On a js script, I have a div which I add dynamically some childs. So from the beginning, I can't know how many childs my div will contains.
When I try to get the innerHTML of my div container, I only obtains the html of the div. Not the html of the node.
How can I get the innerHTML of the whole components, through the childs ?
On a js script, I have a div which I add dynamically some childs. So from the beginning, I can't know how many childs my div will contains.
When I try to get the innerHTML of my div container, I only obtains the html of the div. Not the html of the node.
How can I get the innerHTML of the whole components, through the childs ?
Share Improve this question edited Jan 13, 2016 at 7:43 Marv 75812 silver badges29 bronze badges asked Jan 13, 2016 at 7:36 M. OznM. Ozn 1,2104 gold badges23 silver badges48 bronze badges 03 Answers
Reset to default 11Try this:
document.getElementById('MyId').outerHTML
This gets all the html of the element, inside and itself.
.outerHTML
for outer, .innerHTML
for inner.
Using outerHTML
will do the trick.
document.getElementById('YourId').outerHTML