gpt4 book ai didi

javascript - 如何使用 jquery 选择和删除/隐藏一个 div?

转载 作者:行者123 更新时间:2023-11-28 18:32:52 24 4
gpt4 key购买 nike

我试图在 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:

<div class="wrapper">

<!-- image -->
<div class="image" style="position: relative; left: 0; top: 0;">

<a href="/partners/Business/forbes">
<img src="http://videomuncher.com/static3/forbes.png" style="position: relative; width: 150px; top: 0; left: 0;">
</a>


<!-- already fav div -->
<div class="already_favorited">
<!-- fav content -->
<p class="already_fav_content">Added</p> <!-- end fav content -->
</div>
<!-- end already fav div -->

<!-- munchbutton div -->
<div class="munchbutton" style="display: none;">
<form method="post" action="/munch_video/ " class="removebutton"><div style="display:none"><input type="hidden" name="csrfmiddlewaretoken" value="dKrS8NzqPWFLM6u8wJrAeid4nGw1avGK"></div>
<input type="hidden" value="Channel" class="playlist">
<input type="hidden" value="forbes" class="video_id">
<input type="hidden" value="forbes" class="video_title">
<input type="hidden" value="remove_video" class="remove">

<input type="submit" class="btn btn-danger" value="Remove">
</form>
</div>
<!-- end munchbutton div -->

<!-- fav div -->
<div class="fav">
<!-- fav content -->
<p class="fav_content">Added</p> <!-- end fav content -->
</div>
<!-- end fav div -->

</div>
<!-- end image div -->

</div>

最佳答案

它没有失败,因为选择器是错误的

    $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();

关于javascript - 如何使用 jquery 选择和删除/隐藏一个 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13794241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com