简体   繁体   中英

Get the whole innerHTML (parent + child)

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 ?

Try this:

document.getElementById('MyId').outerHTML

This gets all the html of the element, inside and itself.

在此输入图像描述


.outerHTML for outer, .innerHTML for inner.

使用outerHTML就可以了。

document.getElementById('YourId').outerHTML

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM