Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Web HTMLStyleElement API | StyleElement type property

  • Last Updated : 31 Jul, 2019

In Web API there are style elements which have a type attribute. To fetch this type attribute we use HTMLStyleElement.type property, which returns the type of the current style.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

getType = style.type;

Example: get the type attribute.




<!DOCTYPE html>
<html>
  
<head>
  
    <style>
        a:focus {
            background-color: magenta;
        }
    </style>
    <link id="Link"
          rel="stylesheet" 
          type="text/css" 
          media="screen" />
    
    <script type="text/javascript">
        function gettype() {
            var label = 
                document.getElementById('Link');
  
            document.getElementById('type').innerHTML = 
              label.type;
  
        }
    </script>
  
</head>
  
<body>
    <center>
  
        <h1 style="color:green;">  
                GeeksForGeeks  
            </h1>
  
        <h2>HTML StyleElement type property</h2>
        <button onclick="gettype ();" 
                id="btn">
          Get type
      </button>
        <p id='type'></p>
    </center>
</body>
  
</html>

Output:
Click the button:

When the button is clicked:

Supported Browsers:

  • Google Chrome
  • Edge 12
  • Firefox
  • Safari
  • Opera



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!