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 ?
If we have a <p> inside a <div> element, the <div> is the parent of the <p> and the <p> is the child of the <div> <div> <p></p> </div>
The Element property innerHTML gets or sets the HTML or XML markup contained within the element. To insert the HTML into the document rather than replace the contents of an element, use the method insertAdjacentHTML() .
'innerHTML' Presents a Security Risk The use of innerHTML creates a potential security risk for your website. Malicious users can use cross-site scripting (XSS) to add malicious client-side scripts that steal private user information stored in session cookies. You can read the MDN documentation on innerHTML .
Try this:
document.getElementById('MyId').outerHTML
This gets all the html of the element, inside and itself.
.outerHTML
for outer, .innerHTML
for inner.
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