javascript - id attribute in html template tag - Stack Overflow

So, I'm diving into the HTML5 template tag, as a possible future solution to my web application pr

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 badges
Add a ment  | 

2 Answers 2

Reset to default 8

Can 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

相关推荐

  • javascript - id attribute in html template tag - Stack Overflow

    So, I'm diving into the HTML5 template tag, as a possible future solution to my web application pr

    17小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信