So, I'm diving into the HTML5 template tag, as a possible future solution to my web application problems. One thing that I don't seem to find is: Can you use the id attribute inside the template tag?
The template can be reused, but ids can't be. So using the same template multiple times (which is why they were invented in the first place) will result in invalid HTML, theoretically. Any official answers?
So, I'm diving into the HTML5 template tag, as a possible future solution to my web application problems. One thing that I don't seem to find is: Can you use the id attribute inside the template tag?
The template can be reused, but ids can't be. So using the same template multiple times (which is why they were invented in the first place) will result in invalid HTML, theoretically. Any official answers?
Share Improve this question edited Jun 25, 2018 at 10:58 Supersharp 31.2k11 gold badges102 silver badges147 bronze badges asked Apr 26, 2015 at 20:06 DavidDavid 1,24612 silver badges23 bronze badges2 Answers
Reset to default 8Can you use the id attribute inside the template tag.
Yes, however:
The template can be reused, but id's can't be.
Correct.
So using the same template multiple times (which is why they were invented in the first place) will result in invalid HTML, theoretically.
Yes. Don't do that. Make sure the IDs are unique before you add them to the main DOM. You could edit them in the template's DOM before you append it to the main DOM.
If you will stamp the template into the main document, the IDs must be unique, however, if you are stamping the template into a shadow root, then you can re-use IDs within the shadow DOM.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742296939a4417311.html
评论列表(0条)