Why does the following return 0?
<p id="g">
<div>kk</div>
<div>ee</div>
<div>jff</div>
</p>
<script type="text/javascript">
var ii = document.getElementById("g");
var hh = ii.getElementsByTagName('div');
document.write(hh.length);
</script>
Because you can’t have a
<div>in a<p>. Paragraphs can only have inline elements as children.As soon as the parser encounters a
<div>, it auto-closes the<p>.Compare