开发者

save jquery selector result into array

开发者 https://www.devze.com 2023-01-16 03:02 出处:网络
I\'m trying to save a jquery selector\'s result into an array so I can reference each element later. I tried this...

I'm trying to save a jquery selector's result into an array so I can reference each element later.

I tried this...

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); //fad开发者_如何学Ce out the last slide, reveals next one

Currently, it's not letting me run any JQuery functions on the array instances. What is the correct way to store and reference JQuery selector results?

Thank you.


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

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


The problem is on the last line, it should be:

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

精彩评论

暂无评论...
验证码 换一张
取 消