label {
display: block;
width: 156px;
cursor: pointer;
padding-right: 6px;
padding-bottom: 1px;
}
<label for="email">{t _your_email}:</label>
I wish to select the label based on the 'for' attribute to make layout changes.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The selector would be
label[for=email], so in CSS:…or in JavaScript using the DOM:
…or in JavaScript using jQuery:
It’s an attribute selector. Note that some browsers (versions of IE < 8, for instance) may not support attribute selectors, but more recent ones do. To support older browsers like IE6 and IE7, you’d have to use a class (well, or some other structural way), sadly.
(I’m assuming that the template
{t _your_email}will fill in a field withid="email". If not, use a class instead.)Note that if the value of the attribute you’re selecting doesn’t fit the rules for a CSS identifier (for instance, if it has spaces or brackets in it, or starts with a digit, etc.), you need quotes around the value:
They can be single or double quotes.