Javascript DOM HTML Meta Object create

Introduction

We can create a <meta> element via the document.createElement() method:

var x = document.createElement("META");

Click the button to create a META element.

View in separate window

<!DOCTYPE html>
<html>
<head>
</head>//from w w  w .  jav  a  2 s  .  com
<body>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.createElement("META");
  x.setAttribute("name", "description");
  x.setAttribute("content", "this is a test");
  document.head.appendChild(x);

  document.getElementById("demo").innerHTML = "created a META element in the HEAD section of your document.";
}
</script>

</body>
</html>



PreviousNext

Related