As Rob suggested, explore what you can do with the selectors available in
jQuery. But if those don't do the trick, keep in mind that the jQuery result
object is an array. If you want to do something unusual with it that isn't
provided by the jQuery selectors, you can access the array elements directly
with an ordinary loop or any other code you want to write.
 
This typical jQuery code:
 
    // Iterate through all elements with class "foo"
    $('.foo').each( function() {
        var element = this;
        // do something with element
    }
 
is essentially the same as:
 
    // Iterate through all elements with class "foo"
    var $foo = $('.foo');
    for( var i = 0, n = $foo.length;  i < n;  ++i ) {
        var element = $foo[i];
        // do something with element
    }
 
Once you access the array elements directly like this, you have the
flexibility to do whatever you want in your code. As a silly example:
 
    // Iterate through the middle third of the
    // "foo" elements, in reverse order
    var $foo = $('.foo'), n = $foo.length;
    var first = n / 3, last = n * 2 / 3;
    for( var i = last - 1;  i >= first;  i-- ) {
        var element = $foo[i];
        // do something with element
    }
 
-Mike



  _____  

From: Olivier Percebois-Garve


I want to loop through the jquery array of objects,
stop to loop when it finds the first match,
and then continue to loop with another search.

In another language I would set a var found = false;
before the loop and then set it to true in the loop,
but with chaining I'm not sure how to do.
Any idea ?

Olivier


Reply via email to