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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 Nov, 2021
Like Article
Save Article