Javascript DOM HTML Object name Property set

Introduction

Change the name of an <object> element:

document.getElementById("myObject").name = "newObjName";

Click the button to change the name of the object.

View in separate window

<!DOCTYPE html>
<html>
<body>

<object id="myObject" 
        width="100" 
        height="100" 
        data="video.mp4" 
        name="obj1"></object>

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

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

<script>
function myFunction() {/*  w  w  w  .ja v  a2 s .com*/
  document.getElementById("myObject").name = "newObjName";
  document.getElementById("demo").innerHTML = "The name of the object was changed";
}
</script>

</body>
</html>



PreviousNext

Related