Skip to content
Related Articles

Related Articles

HTML | DOM Meta Object

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 24 Nov, 2021

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: 
 

html




<!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>             

Output:
Before Clicking On Button: 
 

After Clicking On Button: 
 

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

html




<!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>

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
Recommended Articles
Page :

Start Your Coding Journey Now!