简体   繁体   中英

how to select parent div with jquery

I have applied this jquery

HTML :

    <div class="slider sliderclick" style="left: -200px;">
        <div class="button-wrap">
            <div class="content-wrap" id="button-1">Special Offer Content</div>
            <div class="controller">
                <div>
                    <a href="#buttton-1">Special Offer</a>
                </div>
            </div>
        </div>
    </div>      
</div>

JS :

jQuery(document).ready(function () {
    jQuery(".controller a").click(function () {        

        jQuery('.slider').animate({left:'0px'},1000);
        //tried this but not worked
        //jQuery(this).parent('.slider').animate({left: '0px'},1000);
        return false;

    });

});

demo

You may use closest in your case :

jQuery(this).closest('.slider').animate({left: '0px'},1000);

Demonstration

您应该使用父选择器,在此处查看文档: http : //api.jquery.com/parent-selector/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM