10

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?

Sampson
  • 265,109
  • 74
  • 539
  • 565

2 Answers2

15

Have you tried:

$.closest("td, div")

?

cletus
  • 616,129
  • 168
  • 910
  • 942
  • 1
    So simple I should be ashamed ;) For some reason I failed to consider that $.closest() takes a regular selector like everything else. – Sampson Aug 31 '09 at 01:00
  • Did it work? I wasn't sure it would. If it does, it'd be good to know cos I could see it being useful. – cletus Aug 31 '09 at 01:03
0

As an alternative to what cletus mentioned, what is wrong with simply:

$("#textareaId").parent() 
Marc
  • 9,254
  • 2
  • 29
  • 31