Javascript Reference - HTML DOM Embed Object








The Embed object represents an HTML <embed> element.

Embed Object Properties

Property Description
Sets or gets the height attribute in an embed element
src Sets or gets the src attribute in an embed element
type Sets or gets the type attribute in an embed element
width Sets or gets the width attribute in an embed element

Standard Properties and Events

The Embed object supports the standard properties and events.

Example

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


<!DOCTYPE html>
<html>
<body>
<embed id="myEmbed" src="notExist.swf">
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w  ww  .  java 2 s.com-->
    var x = document.getElementById("myEmbed").src;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

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


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

</body>
</html>

The code above is rendered as follows: