Reference $(this).parent with class name of 'x'

d-_-b picture d-_-b · Aug 13, 2012 · Viewed 59.8k times · Source

In jquery, how can I refer to the parent of $(this) element with a class of 'abc'?

Answer

j08691 picture j08691 · Aug 13, 2012

Like this:

$(this).parents('.abc');

or

$(this).parent('.abc');

or

$(this).closest('.abc');

.parent() and .parents() are similar except that .parent() only travels up one level in the DOM tree.