+...">

HTML ID attribute in close tag?

This code is in order where I ID close the div:

<html> <body> <div id="main"> </div id=main"> </body> </html> 
+2
html css
source share
5 answers

Not. The id attribute should only be in the opening tag.

If you do this for readability, you might want to use HTML comments and the source tab:

 <html> <body> <div id="main"> </div> <!-- close main div --> </body> </html> 
+11
source share

Invalid: validator prints

Row x, Column y: The end tag had attributes.

If you want to do this in order to avoid the confusion of multiple closing tags, just use the comment to find out which tag belongs to which element:

 </div> <!-- #main --> 
+4
source share

This syntax is not valid in all markup languages that I know about .
Closing tags cannot have attributes.

+2
source share

No, this is not valid. but you can do something similar if this is readability after you.

 <html> <head> <title></title> </head> <body> <div id="main"> </div><!-- end of main --> </body> </html> 
+1
source share

Recently, to perform maintenance on older code, I found that using comments at the end of a div tag really made it difficult to comment on large sections of code, because HTML does not have shadow comment tags. So, I got the habit of modifying comments in hidden spaces at the end of large div blocks.

 <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 posted the HTML5 "HIDDEN" attribute here, so if others change it and add text for some reason, the content will usually remain hidden. I did it ALL CAPS so that it looked a little bigger, as if shouting "COMMENT HERE!". Yes, it creates a DOM element, which should now be supported by the browser, but its low price for payment with the active development of the site.

Using the "end-of-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 page blocks to help with development. Perhaps it will be useful for others.

0
source share

All Articles