chetan mehta
chetan mehta

Reputation: 369

Ambiguity in innerHTML property

<div><p><p></p></p></div>
<script>
alert(document.getElementsByTagName("div")[0].innerHTML);
</script>

Execute the code

I found something unusual the alert shows me 3<p> elements. Well I have declared only two. its actually showing one more than declared. Someone explain this.

Upvotes: 0

Views: 38

Answers (1)

nozari
nozari

Reputation: 504

you can't have paragraphs inside paragraphs. try this:

<div><p></p><p></p></div>
<script>
alert(document.getElementsByTagName("div")[0].innerHTML);
</script>

Upvotes: 2

Related Questions