- This topic is empty.
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?
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:
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.