Skip to main content

Forums

This topic contains 4 replies, has 0 voices, and was last updated by  paperrobots 7 years, 11 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #32579

    paperrobots
    Participant

    Is there an easier way to select a previous element with jquery rather then chaining .parent().parent().parent()? I have multiple list items that each need individual functionality. So I’m trying to target elements within each one based on the button clicked. What would be the easiest way to target other elements?










  • #47883

    You can use the parents() selector as opposed to the parent() selector to travel up the dom multiple levels. In this case, are you just looking for the list item? Maybe something like:

    $(this).parents('li').prev();
    #47634

    @mottie – good call there. Always better safe then sorry.

    #47609

    paperrobots
    Participant

    Nice I wasn’t aware of .closest! It didn’t work with the .prev() though. So I took it off and it seems to be working.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star