Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why this "<p><div><br></div></p>" is shown strange in DOM? [duplicate]

Tags:

html

dom

When you put <p><div></br></div></p> into body, you will get the strange DOM structure like:

<p></p>
<div></br></div>
<p></p>

Why does this happened? It seems that when <p> contains a block element this will happen.

like image 656
Tom Avatar asked Dec 20 '22 01:12

Tom


1 Answers

According to the spec, p cannot have nested block elements, so the HTML parser automatically closes it before the div when building the DOM.

like image 56
Thilo Avatar answered Jan 05 '23 09:01

Thilo