Javascript Reference - HTML DOM Meta name Property








The name property sets or gets a name for the information in the content attribute.

Browser Support

name Yes Yes Yes Yes Yes

Syntax

Return the name property.

metaObject.name 

Set the name property.

metaObject.name='application-name|author|description|generator|keywords'

Parameter

Value Description
application-name Set the name of the Web application that generates the page
author Set the name of the author of the document.
description Set description of the page.
generator Set the software packages used to generate the document
keywords Set a comma-separated list of keywords relevant to the page




Return Value

A String type value representing the name of the meta data.

Example

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="tutorials">
<meta name="keywords" content="HTML,CSS">
<meta name="author" content="java2s.com">
</head><!--   ww w  .  ja va 2 s  .  c om-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementsByTagName("META");
    var i;
    for (i = 0; i <x.length; i++) {
        console.log("Name of "+(i+1)+". meta tag: "+x[i].name);
    }
}
</script>

</body>
</html>

The code above is rendered as follows: