Reputation: 61
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 ?
Upvotes: 0
Views: 35
Reputation: 35
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.
Upvotes: 1