Open In App

HTML DOM embeds Collection

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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() {
            let 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() {
            let 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 64.0 & above
  • Internet Explorer 4.0
  • Microsoft Edge 12.0
  • Firefox 1.0 & above
  • Opera 51.0
  • Safari 10.1


Last Updated : 05 Jul, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads