为什么你会给一个样式标签的id [英] Why would you give a style tag an id

查看:84
本文介绍了为什么你会给一个样式标签的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,您已经注意到一些网站给风格标签的id如:

Hi have noticed a few sites that give the style tag an id such as:

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

任何人都可以解释为什么要这样做以及doin的好处吗?

Can anyone explain firstly why you would do this and also the benefits of doin so?

推荐答案

所以你可以引用它(就像任何其他元素一样),例如

So you can reference it (just like any other element), i.e.

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

这篇关于为什么你会给一个样式标签的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆