JQuery: Closest div that has an ID

mike picture mike · Feb 23, 2011 · Viewed 50.8k times · Source

How would you write the Jquery to get the closest div that actually has an ID defined?

Answer

gor picture gor · Feb 23, 2011

You should use has attribute selector. This sample should do the work:

$('selector').closest('[id]')