Thanks for your answers. An ordinary loop is what I need.
The reason why I need this is because I want the extend Jake's textNodes
plugin
in order to highlight/animate a word made out of letters from a text.
For instance for the word "selector":
Lorem ipsum dolor *s*it amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laore*e*t dolore magna aliquam erat
vo*l*utpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip *e*x ea commodo
*c*onsequat. Duis autem vel eum iriure dolor in hendrerit in vulputate
velit esse molestie consequa*t*, vel illum dolore eu feugiat nulla
facilisis at vero er*o*s et accumsan et iusto odio dignissim qui blandit
p*r*aesent luptatum zzril delenit a
I think I need a lot of loops in order to choose letters not too close
to eachother, etc
Thanks for showing me the right direction
Olivier
Michael Geary wrote:
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