Well, if you have an array with the elements you could do:
let elementsArray = document.querySelectorAll("whatever");
elementsArray.forEach(function(elem) {
elem.addEventListener("input", function() {
//this function does stuff
});
});
More Related Contents:
- How to pass arguments to addEventListener listener function?
- Remove all child elements of a DOM node in JavaScript
- Changing website favicon dynamically
- What is the difference between children and childNodes in JavaScript?
- How to append text to a “?
- How do I do OuterHTML in firefox?
- How to access CSS generated content with JavaScript
- jQuery DOM changes not appearing in view source
- JavaScript get element by name
- Accessing the content of other tabs in a browser
- Is there a way to select sibling nodes?
- How to detect when an iframe has already been loaded
- How do I put codes from jsfiddle.net into my website?
- JavaScript: How to get parent element by selector?
- Screen Scraping from a web page with a lot of Javascript [closed]
- What is better, appending new elements via DOM functions, or appending strings with HTML tags?
- Attach event listener through javascript to radio button
- Check whether HTML element has scrollbars
- Why is React’s concept of Virtual DOM said to be more performant than dirty model checking?
- Why doesn’t Node.js have a native DOM?
- How to append a childnode to a specific position
- Simple way to get element by id within a div tag?
- How can I detect a Scrollbar presence ( using Javascript ) in HTML iFrame?
- How to add a onclick event to an element using javascript
- Test if an element can contain text
- Load javascript async, then check DOM loaded before executing callback
- How to check null objects in jQuery
- Screen Coordinates of a element, via Javascript
- Vanilla JS event delegation – dealing with child elements of the target element
- Manually dispatchEvent DOMContentLoaded