SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery: nextAll() then jump to next div

    I'm trying to use jQuery's nextAll() across multiple divs:

    Code:
    <div class='divA'>
        <span class='a b'></span>
        <span class='a'></span>
        <span class='a b'></span> (Start searching for next 'b' class)
        <span class='a'></span>
        <span class='a'></span> (No more 'b' classes are found)
    </div> (So jump to next div)
    <div class='divA'>
        <span class='a'></span>
        <span class='a b'></span> (And find this one)
        <span class='a'></span>
        <span class='a b'></span>
        <span class='a'></span>
    </div>
    Any Ideas?

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Try this, i haven't tested it but it should work.

    Code JavaScript:
    $('.divA').each(function() {
        $('span', this)
            .nextAll()
            .hasClass('b')
            .css('background-color', 'red');
    });

  3. #3
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well it didn't work for my particular application but it did lead me to a solution, and I should at least thank you for that

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    No worries, if it helped get you a solution im happy.


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
  •