Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jquery选择和删除/隐藏div?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 如何使用jquery选择和删除/隐藏div?

Javascript 如何使用jquery选择和删除/隐藏div?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,在AJAX成功时,我试图删除一个div,但在这样做时遇到了麻烦。成功后,我看到“添加”字样出现两次,因为我无法正确选择包含它的2个div。关于如何正确选择它有什么建议吗? javascript: success: function(message){ alert("Deleting!"); $this.closest('.image').find('.already_fav_content p').removeC

在AJAX成功时,我试图删除一个div,但在这样做时遇到了麻烦。成功后,我看到“添加”字样出现两次,因为我无法正确选择包含它的2个div。关于如何正确选择它有什么建议吗? javascript:

 success: function(message){                         
        alert("Deleting!");
        $this.closest('.image').find('.already_fav_content p').removeClass(); #doesn't work

        $this.closest('.image').find('.fav_content p').hide(); #doesn't work

        $this.closest('.image').find('.removebutton').hide(); #works

        $this.closest('.image').find('.already_favorited').removeClass(); #works

        $this.closest('.image').find('.fav').removeClass(); #works


div.fav{
    display: none;
    position:absolute; /* absolute position (so we can position it where we want)*/
    bottom:0px; /* position will be on bottom */
    left: 0px;
    /* styling bellow */
    background-color:#E99C07;
    font-family:  "Arial Black", Gadget, sans-serif;
    font-size:18px;
    font-weight:900;
    color:white;
    opacity:0.75; /* transparency */
    filter:alpha(opacity=70); /* IE transparency */
}
p.fav_content{
    padding:10px;
    margin:0px;
}

div.already_favorited{
    position:absolute; /* absolute position (so we can position it where we want)*/
    bottom:0px; /* position will be on bottom */
    left: 0px;
    /* styling bellow */
    background-color:#E99C07;
    font-family:  "Arial Black", Gadget, sans-serif;
    font-size:18px;
    font-weight:900;
    color:white;
    opacity:0.75; /* transparency */
    filter:alpha(opacity=70); /* IE transparency */
}
p.already_fav_content{
    padding:10px;
    margin:0px;
}                    
html:


已添加内容
添加了内容

由于选择器错误,所以没有写入

    $this.closest('.image').find('.already_fav_content p').removeClass(); #doesn't work

    $this.closest('.image').find('.fav_content p').hide(); #doesn't work
改成

    $this.closest('.image').find('p.already_fav_content').removeClass();

    $this.closest('.image').find('p.fav_content').hide();

它没有写出来,因为选择器错了

    $this.closest('.image').find('.already_fav_content p').removeClass(); #doesn't work

    $this.closest('.image').find('.fav_content p').hide(); #doesn't work
改成

    $this.closest('.image').find('p.already_fav_content').removeClass();

    $this.closest('.image').find('p.fav_content').hide();