<html> <head> <script src="jquery-1.2.js"></script> <script> $(document).ready ( function () { $("#previous").click ( function () { var current; $("#items .item").each( function (index, element) { if ("red" === $(element).css("color")) { current = index; } } ); $("#items .item").each( function (index, element) { if (index === current - 1) { $($("#items .item")[current]).css("color", ""); $(element).css("color", "red"); } } ); } ); } ); $(document).ready ( function () { $("#next").click ( function () { var current; $("#items .item").each( function (index, element) { if ("red" === $(element).css("color")) { current = index; } } ); $("#items .item").each( function (index, element) { if (index === current + 1) { $($("#items .item")[current]).css("color", ""); $(element).css("color", "red"); } } ); } ); } ); </script> </head> <body> <div id="items"> <div class="item" style="color: red;"> 1 </div> <div class="item"> 2 </div> <div class="item"> 3 </div> <div class="item"> 4 </div> <div class="item"> 5 </div> <div class="item"> 6 </div> <div class="item"> 7 </div> <div class="item"> 8 </div> <div class="item"> 9 </div> <div class="item"> 10 </div> </div> <button id="previous"> previous </button> <button id="next"> next </button> </body> </html>
2007/9/15, Fabien Schwob <[EMAIL PROTECTED]>: > > > Hello, > > I would like to develop a "next item" in jQuery but I can't find how > to develop it. I have found how to get the offset of an element (with > .offset()), but I can't find how to go to this offset. > > For example the html is : > > <div id="items"> > <div class="item"> > </div> > <div class="item"> > </div> > </div> > > And I will have a "next" and "previous" button to navigate through the > .item. > > Thanks in advance. > > -- > Fabien SCHWOB > -- http://www.goumin.com/ QQ: 443089607 QQ mail: [EMAIL PROTECTED] Skype: huzhenghui Gtalk: huzhengh