10 examples of 'jquery loop through elements by class' in JavaScript

Every line of 'jquery loop through elements by class' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
66function jQueryGenericLoop (elements, cache) {
67 $.each( cache, function ( key, val ) {
68 if ( val.handle ) {
69 jQueryGeneric(elements, val, val.handle.elem);
70 }
71 } );
72}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

34function forEachElementInClass(className, callback, arg) {
35 var references = document.getElementsByClassName(className);
36 for (i = 0; i < references.length; ++i) {
37 callback(references[i], i, arg);
38 }
39}
45function JQueryClosestByClass(element, clazz) {
46 while (element) {
47 if (JQueryHasClass(element, clazz)) {
48 return element;
49 }
50 element = element.parentNode;
51 }
52 return null;
53}
57export function findElementParentByClassName(element, className, includeSelf) {
58 let el;
59 if (includeSelf === false) {
60 el = element.parentElement;
61 } else {
62 /** @type {HTMLElement} */
63 el = (element);
64 }
65 while (el != null && !el.classList.contains(className)) {
66 el = el.parentElement;
67 }
68 return el;
69}
134function getElements(className) {
135 var elements = [];
136 var el = document.getElementsByTagName('DIV');
137 var regexp=new RegExp("\\b"+className+"\\b");
138 for (var i = 0; i < el.length; i++)
139 {
140 if (regexp.test(el[i].className))
141 elements.push(el[i]);
142 }
143 return elements;
144}
12export function queryElementsByClass(
13 selectors: string,
14 parentNode = document
15): any {
16 return parentNode.getElementsByClassName(selectors);
17}
18function find(el, selector) {
19 return selectionToArray(el.querySelectorAll(selector));
20}
206function forEachDomElement(selector, callback) {
207 var elements = document.querySelectorAll(selector)
208 return Array.prototype.forEach.call(elements, callback)
209}
5function $(selector) {
6 return document.querySelectorAll(selector)
7}
20export function getElements(selector) {
21 return [].slice.call(document.querySelectorAll(selector));
22}

Related snippets