Javascript DOM HTML Meta content Property get

Introduction

Return the value of the content attribute of all meta elements:

Click the button to return the value of the content attribute of all meta elements.

View in separate window

<!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 ww  . ja va 2s  .  com*/
<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 + "Content of "+(i+1)+". meta tag: "+x[i].content+"<br>";
  }

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

</body>
</html>

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

The content attribute sets the content of the meta information.

The content property accepts and returns a String type value.

Type Description
String The value of the content attribute of the meta element



PreviousNext

Related