Javascript DOM HTML Object Object create

Introduction

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

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

Click the button to create an OBJECT element with an embedded flash file.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {//from  w w w . j a va2  s .  co m
  var x = document.createElement("OBJECT");
  x.setAttribute("data", "video.mp4");
  x.setAttribute("width", "200");
  x.setAttribute("height", "200");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related