Create a Meta Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Meta

Introduction

You can create a <meta> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
</head>/*w w w .  j  a  v a 2  s. co  m*/
<body>

<button onclick="myFunction()">create a META element</button>

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

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

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

</body>
</html>

Related Tutorials