Javascript 在父DIV下按类查找DIV

Javascript 在父DIV下按类查找DIV,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我在父容器下嵌套了几个DIV元素。当用户单击其中一个cp锚定时,我想修改另一个cp内容上的CSS。我尝试了几十种在堆栈溢出上找到的方法,但由于某些原因,它似乎并没有像预期的那样工作。有人能帮我指出正确的方向吗 下面是我正在使用的示例的一部分 <script type="text/javascript"> $( document ).ready(function() { $('.cp-anchor').click(function(e)

我在父容器下嵌套了几个DIV元素。当用户单击其中一个
cp锚定
时,我想修改另一个
cp内容
上的CSS。我尝试了几十种在堆栈溢出上找到的方法,但由于某些原因,它似乎并没有像预期的那样工作。有人能帮我指出正确的方向吗

下面是我正在使用的示例的一部分

    <script type="text/javascript">

    $( document ).ready(function()
    {
        $('.cp-anchor').click(function(e)
        {
            e.preventDefault();

            $(this).parent().find('cp-content').css('max-height','none');
            $(this).remove();
        });
    });

    </script>

<div class="cp-container">
    <div class="cp-content">
        <table id="tablepress-4">
        </table>
    </div>
    <div class="cp-anchor"><span class="cp-anchor-text">Show Full Contents</span></div>
</div>

$(文档).ready(函数()
{
$('.cp-anchor')。单击(函数(e)
{
e、 预防默认值();
$(this.parent().find('cp-content').css('max-height','none');
$(this.remove();
});
});
展示全部内容

您需要一个
来表示类别选择

//                     v
$(this).parent().find('.cp-content').css('max-height','none');
$(文档).ready(函数(){
$('.cp-anchor')。单击(函数(e){
e、 预防默认值();
$(this.parent().find('.cp content').css('max-height','none');
$(this.remove();
});
});
.cp内容{
最大高度:0;
溢出:隐藏;
}

CP含量
展示全部内容

您需要一个
来表示类别选择

//                     v
$(this).parent().find('.cp-content').css('max-height','none');
$(文档).ready(函数(){
$('.cp-anchor')。单击(函数(e){
e、 预防默认值();
$(this.parent().find('.cp content').css('max-height','none');
$(this.remove();
});
});
.cp内容{
最大高度:0;
溢出:隐藏;
}

CP含量
展示全部内容

在Js中使用以下一行代码:

$(this).parent().find('.cp-content').css('max-height','none');

在Js中,使用以下一行代码:

$(this).parent().find('.cp-content').css('max-height','none');

似乎对我很管用。你想在这里实现什么?问题和提琴中提到的代码是不同的,确切的问题是什么?似乎在提琴中对我有用。你想在这里实现什么?问题和提琴中提到的代码是不同的,确切的问题是什么?哇,我已经从这个开始几个小时了,完全错过了那个。非常感谢你指出我愚蠢的错误!哇,我已经开始在这几个小时,完全错过了。非常感谢你指出我愚蠢的错误!