Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would you give a style tag an id

Tags:

html

css

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?

like image 668
David Avatar asked Sep 26 '10 09:09

David


People also ask

Can a style tag have an ID?

An id on a <style> tag assigns an identifier to the style. The identifier must be unique across the page.

Should I use ID for styling?

Both ID's and classes are perfectly fine to use for CSS styling.

How do you use ID in style tag?

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.

What is ID tag used for?

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).


1 Answers

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 
like image 86
Dan Beam Avatar answered Sep 20 '22 16:09

Dan Beam