SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to loop alternate elements in JQuery

    How to loop alternate elements in JQuery ?

    I see it has each function which loops each elements . But I want every alternate elments to loop starting from an index.

    is it possible in JQuery ?

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,082
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Code javascript:
    $.each(function (i, elem) {
     if (i % 2 == 0) {
      // do something with even elements, or leave empty if nothing needs to be done
     } else {
      // do something with odd elements, or leave empty if nothing needs to be done
     }
    });

    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •