如何用jquery选择父div

时间:2013-07-28 09:20:12

标签: jquery

我已应用此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

2 个答案:

答案 0 :(得分:0)

您可以在案件中使用closest

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

Demonstration

答案 1 :(得分:-1)

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