Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jquery – get prev and next href.

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #38061
    kaffekop
    Member

    Hello.

    I’m trying to get hold of the prev/next-objects when clicking a link from within the #menu.
    I’ve tried all sorts of .prev(), .prevUntil() a.s.o but so far I haven’t had any luck with it :)

    My current layout is:




    jquery:

    $('#menu a').click(function(){
    // get the parent.a object so i can send send it to the #prev container as pageX
    // get the next.a object so i can send it to the #next container as pageX
    });

    If possible the script should ignore the table,tr,td,ul & li items, the menu structur/html can change in the future (its can be user-configured) – if not, no worries :)

    #102820
    noahgelman
    Participant
    $('#menu a').click(function(){
    var theLink = $(this).parent().siblings().children('a').attr('href');
    // do whatever you want with the theLink variable
    });
    #102833
    kaffekop
    Member

    Kinda like that yes, except that it only gets the data in the same td.
    Firebug says:

    clicked: page1 > prev = page2
    clicked: page2 > prev = page1
    clicked: page3 > prev = undefined
    with:
    $('#menu a').click(function(){
    $prev = $(this).parent().siblings().children('a').attr('href');
    console.log( "clicked: " + $(this).attr('href') + " > prev = " + $prev );
    return false;
    });

    The idea is that clicking “page2” will set “prev” = “page1” and “next” = “page3”, clicking “page1” will set “next” to “page2” and “prev” to null, and so on.

    I managed to make a “hey it works” version yesterday that runs a $(‘#menu a’).each and then sets the $prev and $next, but it feels a bit clumsy and php’ish.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.