Create an Output Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Output

Introduction

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Click the button to create an OUTPUT element.</p>

<form id="myForm" oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
  <input type="range" id="a" value="50">100
  +<input type="number" id="b" value="50">=
</form>/*from w  w  w.  j a v a  2  s.  c o m*/

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
    var x = document.createElement("OUTPUT");
    x.setAttribute("name", "x");
    x.setAttribute("for", "a b");
    document.getElementById("myForm").appendChild(x);
    document.getElementById("demo").innerHTML = "output element created.";
}
</script>

</body>
</html>

Related Tutorials