This is probably a pretty pointless question but I reckon it would be useful for many of us.
In this case's scenario, I would like to be able to hide a textbox and its label all in one go, without having to select both element and hiding them individually.
<label for="a">some text:</label>
<input type="text" class="text" id="a" />
So, for the above case, would it be possible to use a simple jQuery command to hide them both together?
HTML input type="hidden"
You could do this
$('label[for=a], input#a').hide();
http://jsfiddle.net/jasongennaro/dYFMU/
[ ]
selects the attribute
. In this case we are targeting a for
attribute that equals a
.
At the same time, we use a ,
to make another selection, the input
with an id=a
.
EDIT
Also, if you needed to do this for multiple labels
and inputs
you could put the label
and id
in an array as follows:
<label for="a">some text:</label>
<input type="text" class="text" id="a" />
<br />
<label for="b">some text:</label>
<input type="text" class="text" id="b" />
<br />
<label for="c">some text:</label>
<input type="text" class="text" id="c" />
js
var a = ['a','b','c'];
for(var i=0; i<a.length; i++){
$('label[for=' + a[i] + '], input#' + a[i]).hide();
}
http://jsfiddle.net/jasongennaro/dYFMU/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With