Open In App

Web HTMLStyleElement API | StyleElement type property

Improve
Improve
Like Article
Like
Save
Share
Report

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:

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


Last Updated : 31 Jul, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads