My favorite is using spread syntax to convert the NodeList to an array and then use forEach
for looping.
var div_list = document.querySelectorAll('div'); // returns NodeList
var div_array = [...div_list]; // converts NodeList to Array
div_array.forEach(div => {
// do something awesome with each div
});
I code in ES2015 and use Babel.js, so there shouldn’t be a browser support issue.
Related Contents:
- Pass mouse events through absolutely-positioned element
- How to check whether a Storage item is set?
- How to set value of input text using jQuery
- How can I capture the right-click event in JavaScript? [duplicate]
- How to focus on a form input text field on page load using jQuery?
- Is there an onSelect event or equivalent for HTML ?
- Unescape HTML entities in JavaScript?
- Enter triggers button click
- How to disable HTML button using JavaScript?
- Capture key press (or keydown) event on DIV element
- How do I create a link using javascript?
- Adding onClick event dynamically using jQuery
- How do I create a new line in Javascript?
- How to programmatically empty browser cache?
- How to get JS variable to retain value after page refresh? [duplicate]
- How to clear a chart from a canvas so that hover events cannot be triggered?
- Resize image with javascript canvas (smoothly)
- Append an element with fade in effect [jQuery]
- Is it possible to access an SQLite database from JavaScript?
- How to simulate a click by using x,y coordinates in JavaScript?
- How to draw polygons on an HTML5 canvas?
- HTML Drag And Drop On Mobile Devices
- How to get an element by its href in jquery?
- JavaScript: get code to run every minute
- make canvas as wide and as high as parent
- How to run html file on localhost?
- Popstate on page’s load in Chrome
- Changing nav-bar color after scrolling?
- Zoom Canvas to Mouse Cursor
- Replace HTML page with contents retrieved via AJAX
- Removing page title and date when printing web page (with CSS?)
- Why do we use for scripts, but not for external CSS?
- Missing .map resource? [duplicate]
- Inlining ECMAScript Modules in HTML
- How to draw photo with correct orientation in canvas after capture photo by using input[type=’file’] in mobile web browser?
- What is the origin and purpose of the variable $data in KnockoutJS?
- How to ONLY trigger parent click event when a child is clicked
- How to hide or disable the google logo, footer, copyright on google maps JavaScript API v3?
- Can you style an html radio button to look like a checkbox?
- HTML Mobile -forcing the soft keyboard to hide [duplicate]
- How to convert characters to HTML entities using plain JavaScript
- How to pass the id of an element that triggers an `onclick` event to the event handling function
- How to get a HTML element from a string with jQuery
- Insert content into iFrame
- Scrolling issues with multiple bootstrap modals
- How to send a pdf file directly to the printer using JavaScript?
- How to clear all input fields in bootstrap modal when clicking data-dismiss button?
- React Native WebView postMessage does not work
- dynamic id ng-repeat
- scrollIntoView vs moveToElement