简体   繁体   English

你为什么要给一个样式标签一个id

[英]Why would you give a style tag an id

Hi have noticed a few sites that give the style tag an id such as: 您已经注意到一些网站为样式标记提供了ID,例如:

<style id=style-id></style>

Can anyone explain firstly why you would do this and also the benefits of doin so? 任何人都可以先解释为什么你会这样做以及doin的好处吗?

So you can reference it (just like any other element), ie 所以你可以引用它(就像任何其他元素一样),即

var styles = document.getElementById('style-id');
// do anything you want, like
styles.parentNode.removeChild(styles); // remove these styles
styles.setAttribute('href', 'alternate-styles.css'); // change the style

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM