HTML | DOM Meta Object

The DOM Meta Object is used to represent the HTML <meta> element. The Meta element is accessed by getElementById().

Properties:

  • Name attribute: This attribute is used to define the name of property.
  • http-equiv attribute: This attribute is used to get http response message header.
  • Scheme attribute: This attribute is used to specify a scheme to interpret the property’s value.
  • Content attribute: This attribute is used to specify properties value.

Syntax:

document.getElementById("ID"); 

Where “id” is the ID assigned to the “meta” tag.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <meta name="keywords" 
          content="Meta Tags, Metadata" />
</head>
  
<body>
    <center>
        <h1>GeeksForGeeks</h1>
        <h2>DOM Meta Object</h2>
        <p>Hello GeeksforGeeks!</p>
        
        <button onclick="myGeeks()">
          Submit</button>
        
        <p id="sudo"></p>
        
        <script>
            function myGeeks() {
                var x = 
                document.getElementsByTagName(
                  "META")[0].content;
                
                document.getElementById(
                  "sudo").innerHTML = x;
            }
        </script>
  </center>
</body>
  
</html>              

chevron_right


Output:

Before Clicking On Button:

After Clicking On Button:

Example-2: Meta Object can be created by using thedocument.createElement Method.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Meta Object </title>
</head>
  
<body>
    <center>
        <h1>GeeksForGeeks</h1>
        <h2>DOM Meta Object</h2>
        <p>Hello GeeksforGeeks!</p>
        <button onclick="myGeeks()">
          Submit</button>
        
        <p id="sudo"></p>
        
        <script>
            function myGeeks() {
                
                // meta tag created
                var g = document.createElement("META");
                
                g.setAttribute("name", "keywords");
                g.setAttribute("content",
                               "Meta Tags, Meta data");
                
                document.head.appendChild(g);
  
                document.getElementById("sudo").innerHTML = 
                  "HTML DOM Meta Object created.";
            }
        </script>
</body>
  
</html>

chevron_right


Output:

Before Clicking On Button :

After Clicking On Button:

Supported Browsers: The browser supported by DOM Meta Object are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.