HTML DOM embeds Collection

Last Updated : 10 Aug, 2026

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

  • [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
<!--Driver Code Starts-->
<!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>
<!--Driver Code Ends-->

    <button onclick="gfg()">Click Me</button>
    <p id="show"></p>
    <script>
        function gfg() {
            let g = document.getElementById("gfgEmbed").src;
            document.getElementById("show").innerHTML = "URL: " + g;
        }
    </script>

<!--Driver Code Starts-->
</body>

</html>
<!--Driver Code Ends-->

Accepted Properties:

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

HTML
<!--Driver Code Starts-->
<!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">
<!--Driver Code Ends-->

    <button onclick="geeks()">Count</button>
    <p id="cnt"></p>
    <script>
        function geeks() {
            let x = document.embeds.length;
            document.getElementById("cnt").innerHTML = 
              "Number of embed Element is:" + x;
        }
    </script>

<!--Driver Code Starts-->
</body>

</html>
<!--Driver Code Ends-->
  • The collection contains every element in the document (in document order). It is live, so it automatically updates if embeds are added or removed from the DOM.
  • Calling document.plugins returns the same object as document.embeds. This exists for historical reasons (older browsers treated plugins and embeds similarly). Both properties always point to the identical collection.
Comment