2

the question I could never find an answer for.

imagine I have a rather the following structure inside of a div:

<div class="BOX"> <ul class="menu" role="navigation"> </li><li><a class="btn" href="#">edit</a></li> <li><a class="btn" href="#">manage</a></li> <li><a class="btn deleteBtn" href="#">delete</a></li> </ul> </div> 

I want to find() div.BOX when I click on the a.deleteBtn. Since I have multiple div.BOX'es on my page I always need to find it with $(this).

so I could easily use trigger.parent().parent().parent() to select the element when inside of the deleteBtn-ClickHandler, but this doesn't look very nice. Is there a cleaner and better way to do so?

thank you.

1
  • Sarah's solution is correct. Additional information why you can't use find. find only searches for elements inside a given element. It's not for "finding" elements "outside" of an element such as parents or siblings. Commented Aug 11, 2011 at 8:32

2 Answers 2

11

try this:

$(this).closest("div.BOX") 
Sign up to request clarification or add additional context in comments.

1 Comment

s/box/BOX/, but apart from that it's the way to go. +1
1

or you can use $(this).parents('div.BOX')

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.