patternjavascriptCritical
jQuery to loop through elements with the same class
Viewed 0 times
withjqueryclasssametheloopthroughelements
Problem
I have a load of divs with the class
Does anyone know how I would do this?
testimonial and I want to use jquery to loop through them to check for each div if a specific condition is true. If it is true, it should perform an action.Does anyone know how I would do this?
Solution
Use each: '
Check the api reference for more information.
i' is the postion in the array, obj is the DOM object that you are iterating (can be accessed through the jQuery wrapper $(this) as well).$('.testimonial').each(function(i, obj) {
//test
});Check the api reference for more information.
Code Snippets
$('.testimonial').each(function(i, obj) {
//test
});Context
Stack Overflow Q#4735342, score: 1379
Revisions (0)
No revisions yet.