gpt4 book ai didi

php - jquery最接近特定div内的图像查找

转载 作者:行者123 更新时间:2023-11-28 04:29:25 24 4
gpt4 key购买 nike

我在页面中使用了以下 HTML

<div class="edge-img-sec">
<img src="img1" alt="edge-icon" class="edge-icon1">
<img src="img2" alt="right-icon" class="edge-icon1-right">
</div>

<div class="edge-img-sec">
<img src="img3" alt="edge-icon" class="edge-icon1">
<img src="img4" alt="right-icon" class="edge-icon1-right">
</div>

Jquery 脚本:-

$( ".edge-img-sec" ).click(function(){
alert('aa');
$(this).closest('img').find('.edge-icon1-right').hide();
});

通过单击 edge-img-sec div,我想隐藏相应的 edge-icon1-right 图像。

我使用了上面的代码。但它不起作用。我在这里做错了什么。请帮我。

最佳答案

你可以像下面那样做(使用 children()):-

$( ".edge-img-sec" ).click(function(){
$(this).children('.edge-icon1-right').hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="edge-img-sec">
<img src="img1" alt="edge-icon" class="edge-icon1"><br>
<img src="img2" alt="right-icon" class="edge-icon1-right"><br>
</div>
<br>
<div class="edge-img-sec">
<img src="img3" alt="edge-icon" class="edge-icon1"><br>
<img src="img4" alt="right-icon" class="edge-icon1-right"><br>
</div>

或者使用find():-

$( ".edge-img-sec" ).click(function(){
$(this).find('.edge-icon1-right').hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="edge-img-sec">
<img src="img1" alt="edge-icon" class="edge-icon1"><br>
<img src="img2" alt="right-icon" class="edge-icon1-right"><br>
</div>
<br>
<div class="edge-img-sec">
<img src="img3" alt="edge-icon" class="edge-icon1"><br>
<img src="img4" alt="right-icon" class="edge-icon1-right"><br>
</div>

关于php - jquery最接近特定div内的图像查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42269600/

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