Meta name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Meta

Description

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

The value of the name attribute depends on the value of the content attribute.

If the http-equiv attribute is set, the name attribute should not be set.

Set the name property:

ValueDescription
application-name Sets the name of the Web application that the page represents
author Sets the name of the author of the document. Example: <meta name="author" content="book 2s">
description Sets a description of the page. Example: <meta name="description" content="Free web tutorials">
generatorSets one of the software packages used to generate the document Example: <meta name="generator" content="FrontPage 4.0">
keywords Sets a comma-separated list of keywords - relevant to the page. Example: <meta name="keywords" content="HTML, meta tag, tag reference">

Return Value

Type Description
String A name for the information in the content attribute

The following code shows how to return the value of the content attribute of all meta elements:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
<head>
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML5,CSS,JavaScript">
<meta name="author" content="your name">
</head>//from   w w  w . j  a v a2 s .  c  o  m

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementsByTagName("META");
    var txt = "";
    var i;
    for (i = 0; i <x.length; i++) {
        txt = txt + "Name of "+(i+1)+". meta tag: "+x[i].name+"<br>";
    }

    document.getElementById("demo").innerHTML = txt;
}
</script>

</body>
</html>

Related Tutorials