Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Add event listener to multiple buttons with the same class

btns = document.getElementsByClassName("saveBtn");
    for (var i = 0; i < btns.length; i++) {
        btns[i].addEventListener("click", function () {
			//Add function here
        });
    }
Comment

addeventlistener on multiple div with class

const boxes = document.querySelectorAll('.box');

boxes.forEach(box => {
  box.addEventListener('click', function handleClick(event) {
    console.log('box clicked', event);

    box.setAttribute('style', 'background-color: yellow;');
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: sort alphabetically javascript 
Javascript :: sort an array by characters length in js 
Javascript :: convert shp to geojson python 
Javascript :: react native get route name 
Javascript :: Show one popover and hide other popovers 
Javascript :: jQuery.easing[this.easing] is not a function 
Javascript :: start peerjs server 
Javascript :: jquery right click 
Javascript :: mongodb pull multiple 
Javascript :: fakepath js 
Javascript :: typeerror object(...) is not a function react useParams 
Javascript :: aos animation react npm 
Javascript :: how to align placeholder in react native 
Javascript :: jquery add td to tr dynamically 
Javascript :: toggle multiple classes jquery 
Javascript :: jquery datepicker re initialize 
Javascript :: laravel ajax delete 
Javascript :: ReferenceError: window is not defined 
Javascript :: how to get prime numbers in javascript 
Javascript :: javascript regex url 
Javascript :: js open file dialog 
Javascript :: How to change htm h1 from nodejs 
Javascript :: how to make a bot react to own message js 
Javascript :: js character certain count 
Javascript :: codeigniter 3 return json response 
Javascript :: capital first letter react 
Javascript :: uppercase and lowercase letters in js 
Javascript :: js append class 
Javascript :: import axios 
Javascript :: module build failed (from ./node_modules/css-loader/dist/cjs.js): 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =