Return the value of the content attribute of all meta elements:
Click the button to return the value of the name attribute of all meta elements.
<!DOCTYPE html> <html> <body> <head> <meta name="description" content="this is a description"> <meta name="keywords" content="test example tutorial"> <meta name="author" content="java2s.com"> </head>/* w w w . java 2 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>
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.
Possible the name properties:
Value | Description |
---|---|
application-name | the name of the Web application that the page represents |
author | the name of the author of the document. Example: <meta name="author" content="java2s.com"> |
description | a description of the page. Search engines can pick up this description. Example: <meta name="description" content="this is a description"> |
generator | the software packages used to generate the document Example: <meta name="generator" content="FrontPage"> |
keywords | a comma-separated list of keywords - relevant to the page Example: <meta name="keywords" content="HTML, CSS, Javascript"> |
The name
property accepts and returns a String type value.