Create a Variable Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Variable

Introduction

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create a VAR element with some text</button>

<script>
function myFunction() {//from   w w  w.  ja va 2s.co m
    var x = document.createElement("VAR");
    var t = document.createTextNode("Some text..");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials