Search code examples
jqueryclosestdom-traversal

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


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?


Solution

  • Have you tried:

    $.closest("td, div")
    

    ?