Omar Juvera
Omar Juvera

Reputation: 12287

Closing tag with ID property

Question: If I close any html tag in this fashion (Including the id property):

<div id="tagid" >...more html
...
</div id="tagid" >

Will it affect the page, or won't like it, or disrupt any W3C rules...how can I put it...will it affect in any way?

Why?: Simply personal preference.
Instead of writing additional comments next to the tag, I simply add the id to help me know WHAT tag is closed -The tag is closed any way, so I guess it won't do anything (or so I think)

PS. FYI, I am a beginner

Upvotes: 13

Views: 9973

Answers (4)

Uncle Code Monkey
Uncle Code Monkey

Reputation: 1786

Quoting my other answer in stackoverflow:

Recently having to perform maintenance on older code, I found that using comments at the end of a div tag really made it difficult to comment out large sections of code thanks to HTML not having nestable comment tags. So, I got into the habit of modifying the comments into hidden spans at the end of large block divs.

<div class="modal fade" id="dialog_edit_group">
    <div class="modal-dialog">
        <div class="modal-content">
            ...HTML content here...
        </div><span title=".modal-content" HIDDEN></span>
    </div><span title=".modal-dialog" HIDDEN></span>
</div><span title=".modal #dialog_edit_group" HIDDEN></span>
<!--
<div class="modal fade" id="dialog_edit_group_OLD">
    <div class="modal-dialog">
        <div class="modal-content">
            ...HTML content here...
        </div><span title=".modal-content" HIDDEN></span>
    </div><span title=".modal-dialog" HIDDEN></span>
</div><span title=".modal #dialog_edit_group_OLD" HIDDEN></span>
-->

I put the "HIDDEN" HTML5 attribute in there so if others modify it and add text for some reason, the contents will usually stay hidden. I made it ALL CAPS so that it would stand out a bit more as if to shout "COMMENT HERE!". Yes, it does create a DOM element that now has to be maintained by the browser, but its a small price to pay during heavy active website development.

Using "end div comments" as such conforms to the HTML standard, gives me greater readability and allows me to use the HTML comment tag to disable large blocks of the page to aid in development. Maybe it will be useful for others as well.

Upvotes: 2

Jason Gennaro
Jason Gennaro

Reputation: 34855

No this is not valid.

While it might not break your code, it could!

You should just use the comments

</div> <!-- closing main content div -->


After checking, this

<div></div id="tagid" >

breaks in the validator

http://validator.w3.org/#validate_by_input


Although not specifically mentioned as illegal, the HTML spec only mentions attributes as appearing within the start tag:

Elements may have associated properties, called attributes, which may have values (by default, or set by authors or scripts). Attribute/value pairs appear before the final ">" of an element's start tag. Any number of (legal) attribute value pairs, separated by spaces, may appear in an element's start tag.

http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2

Upvotes: 16

Mithrandir
Mithrandir

Reputation: 25337

In HTML/XML attributes may only be placed in the start tag of an element. You're producing invalid html.

Upvotes: 1

Ibu
Ibu

Reputation: 43810

here how you close a div:

<div id="tagid" ></div>

if you want to recognize where the tag ends you can simply add a comment:

<div id="tagid" >
   ...
</div><!-- Tagid Ends here -->

Upvotes: 2

Related Questions