JQuery: selector question (parent)

I have this markup:

<ul class=container>

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

</ul>

I am now on a div element ("I'm here"), how can I get a link to? I tried div.parent("li");but didntwork ..

+3
source share
2 answers

Use

closest("li") 

not parent http://docs.jquery.com/Traversing/closest Parent receives only the direct parent.

+4
source

parentused to produce a unique direct antetsereza element that in your case a div.

You must use parentseither closest:

div.parents("li");
+1
source

Source: https://habr.com/ru/post/1724051/


All Articles