“GetElementByTagName JavaScript” Code-Antworten

Dokument Get Element by Tag

var list = document.getElementsByTagName("UL")[0];
list.getElementsByTagName("LI")[0].innerHTML = "Milk";
Awesomered989

GetElementByTagName JavaScript

const btns = document.getElementsByTagName('button');
const btnFirst = btns.item(0);
// to get an item for the HTML collection use indexing, like arrays start
// at index 0
const btnNamed = btns.namedItem('named-btn');
// to get a named item you can use both id & name attributes

btnFirst.onclick = () => {
    console.log('The first item in the collection');
}
btnNamed.onclick = () => {
    console.log('A named item in the collection');
}
ST111

Ähnliche Antworten wie “GetElementByTagName JavaScript”

Fragen ähnlich wie “GetElementByTagName JavaScript”

Weitere verwandte Antworten zu “GetElementByTagName JavaScript” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen