Javascript DOM HTML Meta Object get

Introduction

The Meta object represents an HTML <meta> element.

We can access a <meta> element by using getElementsByTagName():

Click the button to get the content of the meta information.

View in separate window

<!DOCTYPE html>
<html>
<head>
  <meta name="description" content="this is a test">
</head>//from w  w  w  .  j  a  va  2  s . c  o m
<body>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementsByTagName("META")[0].content;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related