我试图隐藏我正在使用查找来检查其内容的东西的父级。我可以将以下内容称为“this”吗?
jQuery('.input-box').find('#preferred-shipping .ps-text').text().trim()
然后像这样使用它?
if(jQuery('.input-box').find('#preferred-shipping .ps-text').text().trim()==='You have backordered items in your cart, please choose a shipping status.') {
jQuery(this).closest('.input-box').hide();
jQuery(this).parent().hide();
}
这是我创建的用于测试它的 JS Fiddle:https://jsfiddle.net/Realto619/qrfytqu9/
最佳答案
$('.input-box').filter(function(){
return $(this).find('#preferred-shipping .ps-text').text().trim()==='You have backordered items in your cart, please choose a shipping status.';
}).hide();
如果过滤器不匹配任何东西,隐藏将被跳过。
关于javascript - 如何通过使用 jQuery 在子项中搜索内容来隐藏父项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48914924/