YouTip LogoYouTip

Coll Doc Embeds

## HTML DOM Document embeds Property The `document.embeds` property returns a collection of all `` elements present in the current document. This property is a read-only collection that represents an `HTMLCollection` of the embedded objects, ordered as they appear in the document source code. --- ## Syntax ```javascript const embedCollection = document.embeds; ``` ### Return Value * An **`HTMLCollection`** object containing all `` elements in the document. * If no `` elements exist, the returned collection is empty (its `length` is `0`). --- ## Properties | Property | Type | Description | | :--- | :--- | :--- | | `length` | `number` | Returns the number of `` elements in the collection. (Read-only) | --- ## Methods | Method | Description | | :--- | :--- | | `` | Returns the `` element at the specified index (starting from `0`). Returns `null` if the index is out of bounds. | | `item(index)` | Returns the `` element at the specified index (starting from `0`). Returns `null` if the index is out of bounds. | | `namedItem(idOrName)` | Returns the `` element with the specified `id` or `name` attribute. Returns `null` if no match is found. | --- ## Code Examples ### Example 1: Count the Number of `` Elements The following example retrieves the total number of `` elements in the document: ```javascript // Get the total count of elements const embedCount = document.embeds.length; console.log("Total embed elements: " + embedCount); ``` ### Example 2: Accessing Specific Embed Elements This example demonstrates how to access individual `` elements using different methods: ```html ``` ### Example 3: Iterating Through the Collection You can loop through the collection of embed elements using a standard `for` loop: ```javascript const embeds = document.embeds; for (let i = 0; i < embeds.length; i++) { console.log(`Embed #${i} Source:`, embeds.src); } ``` --- ## Technical Details | Feature | Specification | | :--- | :--- | | **DOM Version** | DOM Level 3 Core Document Object | | **Return Type** | `HTMLCollection` | | **Live Collection** | Yes (The collection automatically updates if `` elements are added or removed from the DOM) | --- ## Browser Support The `document.embeds` property is fully supported by all modern web browsers: | Feature | Chrome | Edge / IE | Firefox | Safari | Opera | | :--- | :--- | :--- | :--- | :--- | :--- | | **`document.embeds`** | Yes | Yes | Yes | Yes | Yes | --- ## Related Pages * **HTML DOM Reference:** (dom-obj-embed.html) * **HTML Reference:** [HTML `` Tag](/tags/tag-embed.html)
← Coll Doc ScriptsProp Error Name β†’