最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get the whole innerHTML (parent + child) - Stack Overflow

programmeradmin1浏览0评论

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 0
Add a comment  | 

3 Answers 3

Reset to default 11

Try 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
发布评论

评论列表(0)

  1. 暂无评论