Javascript Reference - HTML DOM Meta content Property








The content property sets or gets the value of the content attribute of a meta element.

Browser Support

content Yes Yes Yes Yes Yes

Syntax

Return the content property.

metaObject.content 

Set the content property.

metaObject.content=text

Parameter

Value Description
text The content of the meta information




Return Value

A String type value representing the value of the content attribute of the meta element

Example

The following code shows how to change the value of the content attribute of the third meta element (index 2) in head.


<!DOCTYPE html>
<html>
<body>
<head>
<meta name="description" content="Web tutorials">
<meta name="keywords" content="HTML , CSS">
<meta name="author" content="java2s.com">
</head><!-- www .j av  a  2 s  . c om-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementsByTagName("META")[2].content = "new value";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the value of the content attribute of all meta elements.


<!DOCTYPE html>
<html>
<body>
<head>
<meta name="description" content="Web tutorials">
<meta name="keywords" content="HTML, CSS">
<meta name="author" content="java2s.com">
</head><!--from   w w  w .ja v  a 2 s.co  m-->
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementsByTagName("META");
    var i;
    for (i = 0; i < x.length; i++) {
        console.log("Content of "+(i+1)+". meta tag: "+x[i].content);
    }
}
</script>

</body>
</html>

The code above is rendered as follows: