How can I find a parent with jQuery?

listed in answer

How can I find a parent with jQuery?
0 votes, 0.00 avg. rating (0% score)

ANSWER:

Because you might not be sure of exactly how far the target element is from the current element, and assuming you only want to find one target element:

$(this).closest('.modal-window');
  • parent() selects the immediate-parent element of $(this), returns a jQuery object of one, or none.
  • parents() selects all matching ancestor elements of $(this), returns a jQuery object of one, none or many.
  • closest() selects the first element matching the selector in the DOM ‘tree’ above the $(this), returns a jQuery object of one, or none.

by David Thomas from http://stackoverflow.com/questions/10266582