Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find parents of an element within a certain div

My html code looks like this...

<div class="container">
        <div id="tropical">
            <div class="info">
                <div class="desc">
                    <p>Lorem ipsum.......</p>               
                </div>
                <div class="list_of_fruits">
                    <ul class="list">
                        <li class="fruit">Avocado</li>
                        <li class="fruit">Banana</li>
                        <li class="fruit">Watermelon</li>           
                    </ul>
                </div>
            </div>
        </div>

        <div id="sub_tropical">
            <div class="info">
                <div class="desc">
                    <p>Lorem ipsum.......</p>               
                </div>
                <div class="list_of_fruits">
                    <ul class="list">
                        <li class="fruit">Apple</li>
                        <li class="fruit">Blackberry</li>           
                    </ul>
                </div>
            </div>
        </div>
    </div>

I am trying to get all the parent divs of li with class "fruit" that are within div with id=tropical...

I have done this much so far ...

$(".fruit").parents().filter("div");

but it selects parents of <li> within div with id=sub_tropical

like image 906
Nishan Hitang Avatar asked Jun 13 '14 08:06

Nishan Hitang


1 Answers

USe

$("#tropical").find(".fruit").parents();

$("#tropical").find(".fruit") will get the .fruits containing in #tropical div

like image 107
Anoop Joshi P Avatar answered Sep 22 '22 02:09

Anoop Joshi P