jQuery $.closest() (Or whichever comes first)

closest, dom-traversal, jquery

Solution

Have you tried:

$.closest("td, div")

?

Problem

While working a project tonight, I ended up using one .js resource file for two different pages. One page contains a textarea within a div, and another contains a textarea within a td. Wanting to work with the siblings of this textarea, and other children of its parent, I wondered how you could best implement "closest div or td, whichever comes first" logic via jQuery syntax. What are your guys' suggestions?

Original source