jQuery Ancestor of nested selector -


i have li bunch of stuff in it

<li class="card">                 <div class="thumb">                     <img src="/images/adv-ipanema.png" alt="">                 </div>                 <div class="caption">                     <p class="place">ipanema beach</p>                     <p class="steps">12,000 steps</p>                 </div>                 <div class="buttons">                     <div class="close"></div>                     <div class="up"></div>                     <div class="down"></div>                 </div>             </li> 

what trying target li when div class "up" clicked.

i created simplified proof-of-concept fiddle , able use parent().parent() there must better way, no? tried parentsuntil('li') no avail, unless doing wrong.

try closest()

description
for each element in set, first element matches selector testing element , traversing through ancestors in dom tree.

i.e.

$(this).closest("li") // or $(this).closest(".card") 

n.b. parentsuntil() return parents up (but not including) selector provided


Comments