0

What is the purpose of adding an id attribute to css link tags?

Example:

<style type="text/css" id="some_id_name">
Anna Riekic
  • 728
  • 1
  • 13
  • 30

2 Answers2

2

In HTML 4.01, the id attribute cannot be used with: <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>.

while in HTML5, the id attribute can be used on any HTML element (it will validate on any HTML element.However, it is not necessarily useful).

But the use is like we can reference it like i.e

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

Check

Why would you give a style tag an id

Community
  • 1
  • 1
Arun Bertil
  • 4,598
  • 4
  • 33
  • 59
-2

The id attribute provides a unique identifier for an element within the document.

Note that the id attribute cannot be applied to the following elements in HTML4:

  • base
  • head
  • html
  • meta
  • script
  • style
  • title

The id attribute can be applied to almost anything except above list of elements, but on its own, it doesn’t affect the display of any element on a web page. Compatibility issues relate mostly to the way in which JavaScript is used to access the referenced element (this depends on differences in the ways browsers interpret the Document Object Model) and the support that different browsers provide for CSS.

web2008
  • 914
  • 4
  • 11