Javascript DOM HTML Parameter Object create

Introduction

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

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

Click the button to create an OBJECT and a PARAM element with an embedded audio file.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from  ww  w. java  2 s . c  o  m
  var x = document.createElement("OBJECT");
  x.setAttribute("data", "video.mp4");
  x.setAttribute("id", "myObject");
  document.body.appendChild(x);

  var y = document.createElement("PARAM");
  y.setAttribute("name", "autoplay");
  y.setAttribute("value", "true");
  document.getElementById("myObject").appendChild(y);
}
</script>

</body>
</html>



PreviousNext

Related