Save jquery selector result to array

I am trying to save the result of a jquery selector to 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); //fade out the last slide, reveals next one

Currently, this does not allow me to run any jQuery functions in array instances. What is the correct way to store and reference jQuery selector results?

Thank.

+3
source share
2 answers
var $slides       = $(".slide"),
    current_slide = $slides.length - 1;

$slides.eq( current_slide ).fadeOut(2500);
+3
source

The problem is the last line, it should be:

$(found_slides[current_slide]).fadeOut(2500);
+1
source

Source: https://habr.com/ru/post/1764957/


All Articles