Why does it matter where the closing div tags go here?

Why does it matter where the closing div tags go here?
0.0 0

#1

Code


#2

It’s not clear from your link exactly what you’re asking. Which div tags?


#3

From the example posted, the DIV elements are nested just fine. For proper nesting, “first in, last out” is a decent thought model. Think of it also as a stack of bowls. Improper nesting results in something rather like wires crossing, not to mention visual confusion. Although most browsers are pretty forgiving of bad code, it’s certainly not something to rely on.

<elem1>
   <elem2>
       <elem3>
           content
       </elem3>
   </elem2>
</elem1>

#4

Couldn’t have said it any better! Aha.

Some other notes…
Proper nesting is important in understanding the DOM as well! It will definitely affect your CSS and DOM manipulation if you don’t properly close your divs.


#5

Well if you want you can write that entire code one the same line but that would make it really hard to read.


#6

Thank you very much!