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>
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()
});
Here is a JSFIDDLE .
您需要隐藏父label
元素以隐藏输入元素及其兄弟文本:
$('#wrapper').find("input[value='Slider']").closest('label').hide();
Use .has()
method to checking children of element.
$("label").has("input[value='Slider']").hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <label> <input type="checkbox" value="Slider"> Slider </label> <label> <input type="checkbox" value="Slider2"> Slider2 </label>
You can try this:
$('#wrapper').find("input[value='Slider']").each(function(){
// $(this).hide(); If you want to hide input too
$(this).parent().hide();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.