Let's say I've got this code
<table>
<tr>
<td><input id="foo" type="text"></td>
<td><label for="foo">This is foo</label></td>
</tr>
</table>
This will hide the input:
#foo { display: none;} /* or hidden could work too, i guesss */
How do I hide the label?
You probably have to add a class/id to and then make another CSS declaration that hides it as well.
Without a class or an id, and with your specific html:
Otherwise if you have jQuery
You should give your
<tr>
tag an idfoo_row
or whatever. And hide that insteadIf you give the label an ID, like this:
Then this would work:
Your other options aren't really cross-browser friendly, unless javascript is an option. The CSS3 selector, not as widely supported looks like this:
Despite other answers here, you should not use
display:none
to hide the label element.The accessible way to hide a label visually is to use an 'off-left' or 'clip' rule in your CSS. Using
display:none
will prevent people who use screen-readers from having access to the content of the label element. Using display:none hides content from all users, and that includes screen-reader users (who benefit most from label elements).The W3C and WAI offer more guidance on this topic, including CSS for the 'clip' technique.
If you don't care about IE6 users, use the equality attribute selector.