Markup: Closing div tags

started by Baxter on Jul 13, 2004 — RSS Feed

Baxter Baxter
Posts: 157

Here's a question... I tend to use tableless layout, so I need to closely keep track of what divs do what. Typically, when I close a div tag I put a comment in front of it, like so:

<div id="foo">

blah blah blah
<!-- end foo div --></div>


But a coworker started doing this:

<div id="foo">
blah blah blah
</div id="foo">


Now, I've never seen additional info in a div close tag, but it validates, and I can't see any reason why you can't do it. Anyone have a definitive answer?

Bk Bk
Posts: 6

i suppose the additional text in the end div is treated as a comment by the interpreter, but as it is part of the div, it gives the PSYCHOLOGICAL impression that it really is the end of the "foo" div, whereas you could easily mix up your nesting such that it, in fact, does not end the foo div but rather some other div.  That would perhaps be harder to trobleshoot as it leads the mind into actually believing what it says, which is not necessarily correct.

Baxter Baxter
Posts: 157

See, that's where I'm intrigued by the idea... you can ALWAYS hose the nesting, but this way you at least know what the close tag is SUPPOSED to go to, and it's way less likely to get separated from the comment.

Vladimir Vladimir
Posts: 53

I agree with Baxter. The extra info at the end DIV tag allows you to identify and re-organize the tags so that they will be where you want them to be. I am currently using the first method with comments but it's a big hassle having to do that for every DIV so I only did it for the main DIVs. With the second method, it should be much easier.

Baxter Baxter
Posts: 157

IF, and this is the big if, the second method is valid.

I can't find anything saying you can't do it, but I can't find anything saying you can, either.

Mountie Mountie
Posts: 11

Baxter said:
IF, and this is the big if, the second method is valid.

I can't find anything saying you can't do it, but I can't find anything saying you can, either.


Have you tried running it through the W3C's validator?  That usually catches my semantic boo-boos.

Baxter Baxter
Posts: 157

Of course. And the validator doesn't freak out. But I'm still left with the nagging feeling it can't be right... if it is, why doesn't everyone do it?

Joe Gillespie Joe Gillespie
Posts: 528

One thing you can be sure of, grey areas like this eventually get tightened-up. To make browsers smaller and faster, they are becomming less forgiving. Things that work fine now won't necessarily work a year from now. I would want to see...

<div id ="whatever">...</div id="whatever">

being part of the official CSS3 specs before I would use it - useful as it might seem.

Joe Gillespie Joe Gillespie
Posts: 528

Actually, I've just run a test of this through the W3C validator and it does NOT validate. Neither will GoLive or BBEDit's syntax checkers allow it.

All of them complain that no attributes are allowed in closing tags.

Joe Gillespie Joe Gillespie
Posts: 528

Further to that, you cannot have an id more than once on a page.

Baxter Baxter
Posts: 157

Good points I'm embarrassed I didn't think of. I knew there had to be something I wasn't thinking of with this. Thank you all for putting your heads together.

Now the big question is, how the heck did we get it to validate?

Maskodok Eko Maskodok Eko
Posts: 171

Good points I'm embarrassed I didn't think of. I knew there had to be something I wasn't thinking of with this. Thank you all for putting your heads together.
TOP SEO | Jasa SEO Profesional

TOP SEO | Jasa SEO Profesional RajaPoker88.com Agen Texas Poker Dan Domino Online Indonesia Terpercaya IDRPoker.COM Agen Texas Poker dan Domino Online Indonesia Terpercaya POKERSTAR88.com Agen Texas Poker Dan Domino Online Indonesia Terpercaya D

You must login to reply