Fuxi
Fuxi

Reputation: 7599

jQuery: selector question (parent)

i'm having this markup:

<ul class=container>

    <li rec=1>
        <div>
           <div>
               <div>i'm here</div>
           </div>
        </div>
    </li>

</ul>

now i'm at the div element ("i'm here"), how can i get reference to the li? i tried div.parent("li"); but didntwork ..

Upvotes: 3

Views: 253

Answers (2)

Christian C. Salvad&#243;
Christian C. Salvad&#243;

Reputation: 827436

parent is used to get the unique direct antecesor of an element, which in your case is a div.

You should use parents or closest:

div.parents("li");

Upvotes: 1

stimms
stimms

Reputation: 44064

Use

closest("li") 

rather than parent http://docs.jquery.com/Traversing/closest Parent only gets the direct parent.

Upvotes: 4

Related Questions