tags:

views:

79

answers:

1

Hello,

I want to move to the next from can I use .next()?

var i=0;
$('#next').bind('click',function(){

 $('#id'+i).next();

i++
});
<div style="width=150px;">
<div id=id1></div>
<div id=id2></div>
<div id=id3></div>
<div id=id4></div>
</div>
Next

Thanks Jean

+1  A: 

The .next() gets next sibling, if you have html structure:

<div id=id1></div>
<div id=id2></div>
<div id=id3></div>
<div id=id4></div>

Then, you can walk over each of these divs like this:

$('#id1').click(function(){
 // get next that id2
 $(this).next()..........
});

Edit

Give your divs class also:

<div id=id1 class="test"></div>
<div id=id2 class="test"></div>
<div id=id3 class="test"></div>
<div id=id4 class="test"></div>

Now with JQuery you can loop each of them like this:

var i=0;

$('.test').each(function(){
 // get next and so on
 $('#id'+i).next()..........

 i++;
});
Sarfraz
assuming if I had multiple divs with +i, then how do I do it this way?$('#id'+i).click(function(){ // get next that id2 $(this).next()..........});
Jean
@Jean: give them a class also, see my updated answer.
Sarfraz