Hi have noticed a few sites that give the style tag an id such as:
<style id=style-id></style>
Can anyone explain firstly why you would do this and also the benefits of doin so?
An id on a <style> tag assigns an identifier to the style. The identifier must be unique across the page.
Both ID's and classes are perfectly fine to use for CSS styling.
To use an ID selector in CSS, you simply write a hashtag (#) followed by the ID of the element. Then put the style properties you want to apply to the element in brackets.
The id global attribute defines an identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With