如何使用jQuery隐藏基于子值的标签 [英] How to hide label based on child value using jquery
本文介绍了如何使用jQuery隐藏基于子值的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据值隐藏元素和标签: 我的html代码看起来像这样
I want to hide an element and a label based on value: My html code looks like this
<form id="wrapper">
<label>
<input type="checkbox" value="Slider">
Slider
</label>
</form>
因此,使用jquery我可以找到一个包含value="Slider"
的输入值,但标签仍然保留,因为它不包含任何id
或class
,并且我无法在其中添加任何内容,因此如何我藏起来
So using jquery i can find an input value that contains value="Slider"
but the label still remains, because it it doesn't contain any id
or class
and I can't add anything there, so how can I hide it
$('#wrapper').find("input[value='Slider']").each(function(){
$(this).hide()
});
这是 JSFIDDLE .
推荐答案
您需要隐藏父label
元素以隐藏输入元素及其同级文本:
You need to hide the parent label
element to hide input element and its sibling text:
$('#wrapper').find("input[value='Slider']").closest('label').hide();
这篇关于如何使用jQuery隐藏基于子值的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文