Some IDL attributes are defined to reflect a particular content attribute. This means that on getting, the IDL attribute returns the current value of the content attribute, and on setting, the IDL attribute changes the value of the content attribute to the given value.
The HTMLAllCollection
,
HTMLFormControlsCollection
,
HTMLOptionsCollection
,
interfaces are collections
derived from the HTMLCollection
interface.
The HTMLAllCollection
interface is
used for generic collections
of elements just like HTMLCollection
,
with the exception that its
namedItem()
method returns an HTMLAllCollection
object when
there are multiple matching elements, and that its item()
method can be used as a
synonym for its
namedItem()
method. It is intended only for the legacy
document.all
attribute.
interface HTMLAllCollection : HTMLCollection { // inherits length and item() legacycaller getter object? namedItem(DOMString name); // overrides inherited namedItem() HTMLAllCollection tags(DOMString tagName); };
length
Returns the number of elements in the collection.
item
(index)Returns the item with index index from the collection. The items are sorted in tree order.
item
(name)
item
(name)
namedItem
(name)
namedItem
(name)Returns the item with ID or name name from the collection.
If there are multiple matching items, then an HTMLAllCollection
object
containing all those elements is returned.
Only a
, applet
,
area
, embed
, form
, frame
,
frameset
,
iframe
, img
, and object
elements can have a name for the
purpose of this method; their name is given by the value of their
name
attribute.
tags
(tagName)Returns a collection that is a filtered view of the current collection, containing only elements with the given tag name.
The HTMLFormControlsCollection
interface is used for collections
of listed elements in
form
and fieldset
elements.
interface HTMLFormControlsCollection : HTMLCollection { // inherits length and item() legacycaller getter object? namedItem(DOMString name); // overrides inherited namedItem() }; interface RadioNodeList : NodeList { attribute DOMString value; };
length
Returns the number of elements in the collection.
item
(index)Returns the item with index index from the collection. The items are sorted in tree order.
namedItem
(name)
namedItem
(name)item
(name)Returns the item with ID or name
name from the
collection.
If there are multiple matching items, then a RadioNodeList
object containing all
those elements is returned.
Returns the value of the first checked radio button represented by the object.
Can be set, to check the first radio button with the given value represented by the object.
The HTMLOptionsCollection
interface is used for collections
of option
elements. It is always rooted on a
select
element and has attributes and
methods that manipulate that element's descendants.
interface HTMLOptionsCollection : HTMLCollection {
// inherits item()
attribute unsigned long length; // overrides inherited length
legacycaller getter object? namedItem(DOMString name); // overrides inherited namedItem()
setter creator void (unsigned long index, HTMLOptionElement? option);
void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
void remove(long index);
attribute long selectedIndex;
};
length
[ = value ]Returns the number of elements in the collection.
When set to a smaller number, truncates the number of
option
elements in the corresponding
container.
When set to a greater number, adds new blank option
elements to that container.
item
(index)Returns the item with index index from the collection. The items are sorted in tree order.
namedItem
(name)
namedItem
(name)item
(name)Returns the item with ID or name
name from the
collection.
If there are multiple matching items, then a NodeList
object containing all those elements is returned.
add
(element [, before ] )Inserts element before the node given by before.
The before argument can be a number, in which case element is inserted before the item with that number, or an element from the collection, in which case element is inserted before that element.
If before is omitted, null, or a number out of range, then element will be added at the end of the list.
This method will throw a
HierarchyRequestError
exception if element is an ancestor of the element into which it is to
be inserted.
selectedIndex
[ = value ]Returns the index of the first selected item, if any, or −1 if there is no selected item.
Can be set, to change the selection.
The DOMStringMap
interface represents a set of name-value pairs. It exposes these
using the scripting language's native mechanisms for property
access.
The dataset
attribute on elements exposes the data-*
attributes on the element.
Given the following fragment and elements with similar constructions:
<img class="tower" id="tower5" data-x="12" data-y="5" data-ai="robotarget" data-hp="46" data-ability="flames" src="towers/rocket.png alt="Rocket Tower">
...one could imagine a function splashDamage()
that takes some arguments, the first of
which is the element to process:
function splashDamage(node, x, y, damage) { if (node.classList.contains('tower') && // checking the 'class' attribute node.dataset.x == x && // reading the 'data-x' attribute node.dataset.y == y) { // reading the 'data-y' attribute var hp = parseInt(node.dataset.hp); // reading the 'data-hp' attribute hp = hp - damage; if (hp < 0) { hp = 0; node.dataset.ai = 'dead'; // setting the 'data-ai' attribute delete node.dataset.ability; // removing the 'data-ability' attribute } node.dataset.hp = hp; // setting the 'data-hp' attribute } }
Some objects support being copied and closed in one operation. This is called transferring the object, and is used in particular to transfer ownership of unsharable or expensive resources across worker boundaries.
[NoInterfaceObject] interface Transferable { };
The following Transferable
types exist:
MessagePort
ArrayBuffer
[TYPEDARRAY]DOM3 Core defines mechanisms for checking for interface support, and for obtaining implementations of interfaces, using feature strings. [DOMCORE]
Authors are strongly discouraged from using these, as they are notoriously unreliable and imprecise. Authors are encouraged to rely on explicit feature testing or the graceful degradation behavior intrinsic to some of the features in this specification.