10 examples of 'jquery loop through elements with same class' in JavaScript

Every line of 'jquery loop through elements with same 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
66function jQueryGenericLoop (elements, cache) {
67 $.each( cache, function ( key, val ) {
68 if ( val.handle ) {
69 jQueryGeneric(elements, val, val.handle.elem);
70 }
71 } );
72}
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}
70function hasAtLeastOneClass(element, classList) {
71 for (var i=0; i
20var _loop = function _loop(i) {
21 var link = links[i];
22 if (link.rel === 'preload' && link.getAttribute('as') === 'style') {
23 w.onloadCSS(w.loadCSS(link.href, link, link.getAttribute('media')), function () {
24 return SHORTBREAD_INSTANCE.loaded(link.id);
25 });
26 link.rel = null;
27 }
28};
1function ancestorContainsClass( element, className ) {
2 var contains = false;
3 var curNode = element;
4 while (curNode) {
5 if (typeof curNode.classList !== "undefined") {
6 if (curNode.classList.contains(className)) {
7 contains = true;
8 break;
9 }
10 }
11 curNode = curNode.parentNode;
12 }
13 return contains;
14}
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}
88function haveSameClasses(el1, el2) {
89 return getSortedClassName(el1) == getSortedClassName(el2);
90}
270var _loop = function _loop(i) {
271 var attr = elements[i].getAttribute("on");
272 var action = elements[i].getAttribute("action");
273 elements[i].addEventListener(attr, function () {
274 eval(action);
275 });
276};
168function getElementsByClassName (element, tag, className) {
169 return filter(element.find(tag), x => angular.element(x).hasClass(className));
170}
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}

Related snippets