Closing tag with ID property
Asked Answered
I

4

13

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

Imprimatur answered 16/1, 2012 at 22:12 Comment(1)
Oh, by the way, I know it might be too much to ask but could you please add a documentation that would explaining why or why not it would break my code? -To avoid speculationImprimatur
A
16

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

Alectryomancy answered 16/1, 2012 at 22:15 Comment(2)
FWIW, the HTML5 spec does say it's an error. Specifically, it says "When an end tag token is emitted with attributes, that is a parse error."Poleyn
Yes totally agree with comments that while it may be possible, its against HTML5 spec, so might work but might break at an unknown point in the future if a particular browser gets strict with rendering. You are best rendering with a open and closed comment either static HTML or runtime if added element via JQuery eg <!-- open section and id -->your html<!-- close section and id --> and this is perfectly valid and parseableDoorman
C
2

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 -->
Calcic answered 16/1, 2012 at 22:13 Comment(0)
A
2

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.

Acea answered 11/11, 2014 at 16:54 Comment(0)
E
1

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

Exhort answered 16/1, 2012 at 22:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.