Example of four methods for implementing the circular Nodelist Dom list in native JS: nodelistdom
This article describes four methods for implementing the circular Nodelist Dom list in native JS. We will share this with you for your reference. The details are as follows:
Function $ (id) {return document. getElementById (id);} var _ PAGE = {timeListDom: $ ('timelist')}; var spanDoms = _ PAGE. timeListDom. querySelectorAll ('span '), domLen = spanDoms. length; // Method 1: Native for loop for (var I = 0; I <domLen; I ++) {var v = spanDoms [I]; // do something you want deal with DOM} // Method 2: Array forEach Function Array. prototype. forEach. call (spanDoms, function (v) {// do something you want deal with DOM}); // method 3: Array forEach function []. forEach. call (spanDoms, function (el) {// do something you want deal with DOM el. classList. remove ('active') ;}); // Method 4: Inherit the Array forEach function NodeList. prototype. forEach = Array. prototype. forEach; spanDoms. forEach (function (v) {// do something you want deal with DOM });