Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

getelementbytagname 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');
}
Comment

getelementsbytagname

const collection = document.getElementsByTagName("li");
Comment

PREVIOUS NEXT
Code Example
Javascript :: mutation observer js 
Javascript :: how to get browser url in javascript 
Javascript :: how to do a classname variable and string react 
Javascript :: getype js 
Javascript :: console.log color terminal 
Javascript :: Could not resolve dependency: npm ERR! peer reac 
Javascript :: read json file javascript 
Javascript :: outsystems close feedback message 
Javascript :: how can auto download window print in javascript 
Javascript :: how to take an element out of an array in javascript 
Javascript :: convert military time to standard time javascript 
Javascript :: Dropzone already attached 
Javascript :: convert base64 to uint8array javascript 
Javascript :: javascript autoplay audio 
Javascript :: javascript intellisense not working in vs code 
Javascript :: react input number 
Javascript :: gdscript add child node 
Javascript :: search string in file node 
Javascript :: google script get date without time 
Javascript :: data-widget="pushmenu" collable automatically 
Javascript :: javascript clear all intervals 
Javascript :: sending form data with fetch using js 
Javascript :: update node js mac to latest version 
Javascript :: prime numbers javascript 
Javascript :: vue read url 
Javascript :: how to remove duplicates from array in javascript 
Javascript :: javascript get line number of error 
Javascript :: thinkful 
Javascript :: javascript log Time from Date 
Javascript :: express server template 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =