[jQuery] Re: Running a loop for array numbers
Hi Johnee, Here's one approach (untested): var $e = $('.equipment'); $.each(['1', '2', '5', 'x'], function(i, k) { $e.find('a.i-right' + k) .filter(function(i) { return ( i > 0 && i < 9 ); }) .hide() .end(); }); Cheers, -Jonathan On Wed, Jul 9, 2008 at 3:55 AM, JohneeM <[EMAIL PROTECTED]> wrote: > > Thanks guys much appreciated. > > I tried the last one : > > $('.equipment a.i-right1').filter(function(i) { >return ( i > 0 && i < 9 ); > > }).hide(); > > And it worked. > > For say > > $('.equipment a.i-right1') > $('.equipment a.i-right2') > $('.equipment a.i-right5') > $('.equipment a.i-rightx') > > How would i put that into a loop? > > Thanks. > > On Jul 8, 10:16 pm, "Jonathan Sharp" <[EMAIL PROTECTED]> wrote: > > Hi Johnee, > > > > Another approach would be: > > > > $('.equipment a.i-right1').each(function(i) { > > if ( i > 0 && i < 9 ) { > > $(this).hide(); > > } > > > > }); > > > > or this would work too: > > > > $('.equipment a.i-right1').filter(function(i) { > > return ( i > 0 && i < 9 ); > > > > }).hide(); > > > > Cheers, > > -Jonathan > > > > On Tue, Jul 8, 2008 at 12:00 PM, JohneeM <[EMAIL PROTECTED]> wrote: > > > > > Hi guys how can i run this in a single statement without manually > > > putting in the numbers? > > > > > $('.equipment a.i-right1:eq(1)').hide(); > > > $('.equipment a.i-right1:eq(2)').hide(); > > > $('.equipment a.i-right1:eq(3)').hide(); > > > $('.equipment a.i-right1:eq(4)').hide(); > > > $('.equipment a.i-right1:eq(5)').hide(); > > > $('.equipment a.i-right1:eq(6)').hide(); > > > $('.equipment a.i-right1:eq(7)').hide(); > > > $('.equipment a.i-right1:eq(8)').hide(); > > > > > Note that im skipping the first array [0] due to wanting it to show. > > > > > Also this one : > > > > >$('.performance-parts #content-container > > > a.lightbox:eq(8)').lightBox(); > > >$('.performance-parts #content-container > > > a.lightbox:eq(9)').lightBox(); > > > > > They need to be in their own array as i want to run a seperate > > > lightbox for each image, is this possible? > > > > > Thanks. >
[jQuery] Re: Running a loop for array numbers
Thanks guys much appreciated. I tried the last one : $('.equipment a.i-right1').filter(function(i) { return ( i > 0 && i < 9 ); }).hide(); And it worked. For say $('.equipment a.i-right1') $('.equipment a.i-right2') $('.equipment a.i-right5') $('.equipment a.i-rightx') How would i put that into a loop? Thanks. On Jul 8, 10:16 pm, "Jonathan Sharp" <[EMAIL PROTECTED]> wrote: > Hi Johnee, > > Another approach would be: > > $('.equipment a.i-right1').each(function(i) { > if ( i > 0 && i < 9 ) { > $(this).hide(); > } > > }); > > or this would work too: > > $('.equipment a.i-right1').filter(function(i) { > return ( i > 0 && i < 9 ); > > }).hide(); > > Cheers, > -Jonathan > > On Tue, Jul 8, 2008 at 12:00 PM, JohneeM <[EMAIL PROTECTED]> wrote: > > > Hi guys how can i run this in a single statement without manually > > putting in the numbers? > > > $('.equipment a.i-right1:eq(1)').hide(); > > $('.equipment a.i-right1:eq(2)').hide(); > > $('.equipment a.i-right1:eq(3)').hide(); > > $('.equipment a.i-right1:eq(4)').hide(); > > $('.equipment a.i-right1:eq(5)').hide(); > > $('.equipment a.i-right1:eq(6)').hide(); > > $('.equipment a.i-right1:eq(7)').hide(); > > $('.equipment a.i-right1:eq(8)').hide(); > > > Note that im skipping the first array [0] due to wanting it to show. > > > Also this one : > > > $('.performance-parts #content-container > > a.lightbox:eq(8)').lightBox(); > > $('.performance-parts #content-container > > a.lightbox:eq(9)').lightBox(); > > > They need to be in their own array as i want to run a seperate > > lightbox for each image, is this possible? > > > Thanks.
[jQuery] Re: Running a loop for array numbers
JohneeM wrote: Hi guys how can i run this in a single statement without manually putting in the numbers? $('.equipment a.i-right1:eq(1)').hide(); $('.equipment a.i-right1:eq(2)').hide(); $('.equipment a.i-right1:eq(3)').hide(); $('.equipment a.i-right1:eq(4)').hide(); $('.equipment a.i-right1:eq(5)').hide(); $('.equipment a.i-right1:eq(6)').hide(); $('.equipment a.i-right1:eq(7)').hide(); $('.equipment a.i-right1:eq(8)').hide(); How about $('.equipment a.i-right1:gt(0):lt(10)').hide(); or $('.equipment a.i-right1:not(:first)').hide(); -- Scott
[jQuery] Re: Running a loop for array numbers
Hi Johnee, Another approach would be: $('.equipment a.i-right1').each(function(i) { if ( i > 0 && i < 9 ) { $(this).hide(); } }); or this would work too: $('.equipment a.i-right1').filter(function(i) { return ( i > 0 && i < 9 ); }).hide(); Cheers, -Jonathan On Tue, Jul 8, 2008 at 12:00 PM, JohneeM <[EMAIL PROTECTED]> wrote: > > Hi guys how can i run this in a single statement without manually > putting in the numbers? > > $('.equipment a.i-right1:eq(1)').hide(); > $('.equipment a.i-right1:eq(2)').hide(); > $('.equipment a.i-right1:eq(3)').hide(); > $('.equipment a.i-right1:eq(4)').hide(); > $('.equipment a.i-right1:eq(5)').hide(); > $('.equipment a.i-right1:eq(6)').hide(); > $('.equipment a.i-right1:eq(7)').hide(); > $('.equipment a.i-right1:eq(8)').hide(); > > > Note that im skipping the first array [0] due to wanting it to show. > > > Also this one : > >$('.performance-parts #content-container > a.lightbox:eq(8)').lightBox(); >$('.performance-parts #content-container > a.lightbox:eq(9)').lightBox(); > > They need to be in their own array as i want to run a seperate > lightbox for each image, is this possible? > > > > Thanks. >
[jQuery] Re: Running a loop for array numbers
Try this for the first one: $('.equipment a.i-right1').not(':eq(0)').hide(); For the second one, check out the slice() method. -- Josh - Original Message - From: "JohneeM" <[EMAIL PROTECTED]> To: "jQuery (English)" Sent: Tuesday, July 08, 2008 10:00 AM Subject: [jQuery] Running a loop for array numbers Hi guys how can i run this in a single statement without manually putting in the numbers? $('.equipment a.i-right1:eq(1)').hide(); $('.equipment a.i-right1:eq(2)').hide(); $('.equipment a.i-right1:eq(3)').hide(); $('.equipment a.i-right1:eq(4)').hide(); $('.equipment a.i-right1:eq(5)').hide(); $('.equipment a.i-right1:eq(6)').hide(); $('.equipment a.i-right1:eq(7)').hide(); $('.equipment a.i-right1:eq(8)').hide(); Note that im skipping the first array [0] due to wanting it to show. Also this one : $('.performance-parts #content-container a.lightbox:eq(8)').lightBox(); $('.performance-parts #content-container a.lightbox:eq(9)').lightBox(); They need to be in their own array as i want to run a seperate lightbox for each image, is this possible? Thanks.
[jQuery] Re: Running a loop for array numbers
not knowing your actual HTML I would try something like this: $('.equipment a.i-right1:gt(0)').each(function(){ $(this).hide(); }); loops over the colletion of your tabs or whatever it is except the one that has index 0. read up jquery docs on each() and :gt() for details .
[jQuery] Re: Running a loop for array numbers
$('.equipment a.i-right1:eq(1)').hide(); $('.equipment a.i-right1:eq(2)').hide(); $('.equipment a.i-right1:eq(3)').hide(); $('.equipment a.i-right1:eq(4)').hide(); $('.equipment a.i-right1:eq(5)').hide(); $('.equipment a.i-right1:eq(6)').hide(); $('.equipment a.i-right1:eq(7)').hide(); $('.equipment a.i-right1:eq(8)').hide(); Could be: $('.equipment a.i-right1:lt(9)').hide();