Javascript Reference - HTML DOM Object Object








The Object object represents an HTML <object> element.

Object Properties

Property Description
align Not supported in HTML5. Use style.cssFloat instead.
Sets or gets the alignment of the object
archive Not supported in HTML5.
Used for archive functionality for the object
border Not supported in HTML5. Use style.border instead.
Sets or gets the border around the object
code Not supported in HTML5.
Sets or gets the URL of the file that contains the compiled Java class
codeBase Not supported in HTML5.
Sets or gets the URL of the component
codeType Not supported in HTML5. Set the code type of the object
data Sets or gets the URL of the resource used by the object
declare Not supported in HTML5.
form Returns a reference to the object's parent form
height Sets or gets the height of the object
hspace Not supported in HTML5. Use style.margin instead.
Sets or gets the horizontal margin of the object
name Sets or gets the name of the object
standby Not supported in HTML5.
Sets or gets a message when loading the object
type Sets or gets the content type
useMap Sets or gets the name of a client-side image map
vspace Not supported in HTML5. Use style.margin instead.
Sets or gets the vertical margin
width Sets or gets the width of the object




Standard Properties and Events

The Object object supports the standard properties and events.

Example

We can access an <object> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<object id="myObject" width="400" height="400" data="notExist.swf">
</object><!-- w  w  w  .j  av  a  2  s.c  o  m-->
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myObject").data;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

We can create an <object> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w  ww . j  av a  2  s  . c  om-->
    var x = document.createElement("OBJECT");
    x.setAttribute("data", "notExist.swf");
    x.setAttribute("width", "400");
    x.setAttribute("height", "400");
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows: