May 3, 2011 at 11:42 am #32579
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?
May 3, 2011 at 12:25 pm #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();May 3, 2011 at 3:13 pm #47634May 3, 2011 at 5:12 pm #47609
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.
You must be logged in to reply to this topic.