HTMLCollection namedItem() Metoda
Przykład
Pobierz zawartość elementu P o identyfikatorze "myElement":
function myFunction() {
var x = document.getElementsByTagName("P").namedItem("myElement");
alert(x.innerHTML);
}
Definicja i użycie
Metoda namedItem()
zwraca element o określonym identyfikatorze lub nazwie w HTMLCollection.
Można również użyć metody skróconej, która da ten sam wynik:
var x = document.getElementsByTagName("P")["myElement"];
Obsługa przeglądarki
Method | |||||
---|---|---|---|---|---|
namedItem() | Yes | Yes | Yes | Yes | Yes |
Składnia
HTMLCollection.namedItem(name)
LUB:
HTMLCollection[name]
Wartości parametrów
Parameter | Description |
---|---|
name | Required. The value of the id attribute, or name attribute, of the element you want to return. |
Wartość zwrotu
Obiekt Element reprezentujący element o określonym identyfikatorze lub nazwie.
Zwraca null , jeśli element nie istnieje.
Powiązane strony
HTMLCollection: metoda item()
HTMLCollection: Długość właściwości