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 :: change image src jquery 
Javascript :: javascript stringify an object 
Javascript :: scroll page to top after ajax success 
Javascript :: gettype js 
Javascript :: node colors log 
Javascript :: stringify 
Javascript :: nodejs chaning env variable at runtime 
Javascript :: function sytax js 
Javascript :: convert arguments to array javascript 
Javascript :: owl-carouselslide vertical 
Javascript :: get all input values by class jquery 
Javascript :: react localstorage remove item 
Javascript :: jquery watch checkbox change 
Javascript :: Add event listener to multiple buttons with the same class 
Javascript :: uselocation hook 
Javascript :: start peerjs server 
Javascript :: rectbutton disable 
Javascript :: javascript remove last child element 
Javascript :: node js get file name without extension 
Javascript :: node js sublime text 
Javascript :: clear all intervals javascript 
Javascript :: fetch post data 
Javascript :: array has object with property js 
Javascript :: how to get prime numbers in javascript 
Javascript :: javascript prompt to integer 
Javascript :: set value to element paragraph in javascript 
Javascript :: prevent browser back button jquery 
Javascript :: document is not defined javascript in nuxt js 
Javascript :: jquery change href value 
Javascript :: animate flash jQuery 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =