Javascript DOM HTML Output Object create

Introduction

We can create an <output> element via the document.createElement() method:

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

Click the button to create an OUTPUT element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<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>// w w  w .java2s  .  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 = "The output element was created.";
}
</script>

</body>
</html>



PreviousNext

Related