I have a div with a set of child divs inside

<div id="indiv"> <div>1</div> <div>2</div> <div>2</div> </div> 

all of them can be either hidden or shown all or some of them specifically, the task is to hide everything and show only one of them, there is js who does it - a day in that there is a variable i which contains the index of the element to be shown, on this basis, I first hide all the elements, and then I show only the one that is needed like this:

  $('#indiv').children('div').fadeOut(300); $('#indiv').children('div')[i].fadeIn(300); 

but the elements are hidden, and in the application the necessary one is not shown, given that i contains the corresponding index (in this case from 0 to 2), tell me how to correctly access the child elements by index ??

  • if you access via [i] you will get access to the dom element with that number in the jquery set instead of the jquery object - Sergey Petrashko

1 answer 1

 $('#indiv').children('div').eq(i).fadeIn(300);