alert(document.getElementById('hhh').children[2].outerHTML)
<h1 id = 'hhh'> hhh1 <p id ="ppp"><p>para1</p>para2</p> </h1>
Why h1 have 3 children ?
It should be 2, which are 2 P elements.
Why there's 1 more extra empty P elements ?
Because of the nested P TAG.
<p id ="ppp"><p>para1</p>para2</p>
The above code will be rendered as:
<p id="ppp"></p>
<p>para1</p>
"para2"
<p></p>
I knew this by experience. I haven't dive deep why this is being rendered like this.
hope it's understandable and helped you.
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.