[英]Jquery hide closest(“div”) not working
我有这样的文件上传
<div class="wrapper" style="margin-top:20px;">
<input class="fileUpload" type="file" />
<br />
<div class="image-holder"></div>
<div>
<input style="display:none" class="cancella_immagine" type="button" value="cancella">
</div>
</div>
当我上传图片时,html代码会以这种方式更改
<div class="wrapper" style="margin-top:20px;">
<input class="fileUpload" type="file" />
<br />
<div class="image-holder"></div>
<img src="blabla/image.jpg" class="thumb-image">
<div>
<input style="display:none" class="cancella_immagine" type="button" value="cancella">
</div>
</div>
现在我想使用jQuery函数来隐藏图像,我正在尝试
$(document).on('click', '.cancella_immagine', function() {
$(this).closest('div').find('.thumb-image').hide();
});
但这不起作用
尝试将closest()
与选择器一起使用,
$(document).on('click','.cancella_immagine', function () {
$(this).closest('div.image-holder').find('.thumb-image').hide();
});
或者,您也可以使用.prev()
在其他方面进行.prev()
,
$(document).on('click','.cancella_immagine', function () {
$(this).parent().prev('.thumb-image').hide();
});
如下所示,使用closest('.wrapper')
而不是closest('div')
。
$(document).on('click','.cancella_immagine', function () {
$(this).closest('.wrapper').find('.thumb-image').hide();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.