“Tagname JS” Code-Antworten

Tagname JS

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

Tag -Name JavaScript

var heading = document.getElementsByTagName("h1");
// this gets all the h1 tag from html document
// you can let any tag from html and store in a desired variable for manipulation
aashish-cd

Ähnliche Antworten wie “Tagname JS”

Fragen ähnlich wie “Tagname JS”

Weitere verwandte Antworten zu “Tagname JS” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen