Skip to content
Related Articles

Related Articles

HTML DOM embeds Collection

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 13 Dec, 2021

The DOM embeds collection property in HTML is used to return the collection of all embedded elements. The elements in the collection are sorted that appear in the source code. This property is used for read-only.

Syntax:

document.embeds

Property: This property contains a value length that returns the number of elements in the document.

Methods: The DOM embeds collection contains three methods which are given below:

  • [index]: It is used to return the element of the selected index. The index value starts with 0. It returns NULL if the index value is out of range.
  • item(index): It is used to return the <embed> element of selected index. The index value starts with 0. It returns NULL if the index value is out of range.
  • namedItem(id): It is used to return the <embed> element from the collection with the given id attribute. It returns NULL if the id is not valid.

Return Value: An HTMLCollection Object, representing all <embed> elements in the document. The elements in the collection are sorted as they appear in the source code

Example: This example demonstrates the use of the DOM embeds collection to get the URL for the embedded flash file.

HTML




<!DOCTYPE html>
<html>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>HTML DOM embeds Collection</h3>
    <embed id="gfgEmbed" src="gfg.swf">
    <p>
        Click the button to see the URL
        for the embedded flash file.
    </p>
  
  
    <button onclick="gfg()">Click Me</button>
    <p id="show"></p>
  
  
      
    <script>
    function gfg() {
        var g = document.getElementById("gfgEmbed").src;
        document.getElementById("show").innerHTML = "URL: " + g;
    }
    </script>
</body>
</html>


 Output:

HTML DOM embeds collection example

Accepted Properties:

Example: This example demonstrates the use of DOM embeds collection to get the total count of embed elements.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>DOM embeds Collection</title>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>HTML DOM embeds Collection</h2>
    <embed src="geeksforgeeks.swf">
    <embed src="geeksforgeeks.swf">
    <button onclick="geeks()">Count</button>
    <p id="cnt"></p>
  
  
      
    <script>
    function geeks() {
        var x = document.embeds.length;
        document.getElementById("cnt").innerHTML = 
          "Number of embed Element is:" + x;
    }
    </script>
</body>
</html>


 Output:

Getting the total count of the embed element using DOM embeds collection

Supported Browsers:

  • Google Chrome 93.0 & above
  • Internet Explorer 11.0
  • Microsoft Edge 93.0
  • Firefox 92.0 & above
  • Opera 79.0
  • Safari 14.1


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!