2010-09-15 59 views
3

我想將jquery選擇器的結果保存到數組中,以便稍後可以引用每個元素。將jquery選擇器結果保存到數組中

我想這...

var found_slides = []; //create the array to hold selector results 

found_slides = $(".slide"); //run the selector and store results 

var current_slide = found_slides.length - 1; //find the last slide 

found_slides[current_slide].fadeOut(2500); //fade out the last slide, reveals next one 

目前,這不是讓我在陣列實例上運行任何jQuery函數。什麼是存儲和引用JQuery選擇器結果的正確方法?

謝謝。

回答

3
var $slides  = $(".slide"), 
    current_slide = $slides.length - 1; 

$slides.eq(current_slide).fadeOut(2500); 
+0

啊üHAZ親codez。 – Dan 2010-09-15 20:34:45

1

的問題是最後一行,它應該是:

$(found_slides[current_slide]).fadeOut(2500);