I have a load of divs with the class 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?
I have a load of divs with the class 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?
Try this example
Html
When we want to access those
divs
which hasdata-index
greater than2
then we need this jquery.Working example fiddle
Without jQuery updated
In JavaScript ES6 using spread
...
operatorover a array-like collection given by
Element.querySelectorAll()
you can do it this way
It's pretty simple to do this without jQuery these days.
Without jQuery:
Just select the elements and use the
.forEach()
method to iterate over them: