tags:

views:

80

answers:

7

If I have the following:

             <label for="deletetxt">Delete This Text</label>

What is the 'for' attribute here? Is that the id?

Assuming that I cannot set a class for the label element to style the label element, how do i set css for this element?

A: 

The For tells the label which element to belong to (which really means that when the label is clicked the element will get the focus).

As for your second question - you can use jQuery: if your html is static use $("label:eq(index)") if your html is dynamic and you know the id of the element the label belongs to you can use $("label[for='thatid']")

Ariel
Ha. nuts you got there first!
Glycerine
A: 

HTML Label Tag is used for forms and submittion. it is not the ID, this 'for' should have the same name as the ID of the object connected to it - for example

<form>
<label for='ford'>Ford Car</label>
<input type="radio" name="fordCar" id="ford" />
</form>

Its a usability object really.

Glycerine
A: 

"for" is the id of the form element that the label should be associated with.

You can add an id to the label to reference it directly.

<label for="fname" id="lbl-fname">First:</label>
<input type="text" id="fname" />
simplemotives
A: 

you can set an id as well as a class http://www.w3schools.com/tags/tag_label.asp

the for "Specifies which form element a label is bound to" so when a user clicks on the label it focuses on the target input.

Sniper
+3  A: 

The for attribute contains the ID of the element that the label is for. I always thought this would be quite intuitive...

<label for="SomeTextField" id="SomeLabel">Some text field</label>
<input type="text" id="SomeTextField">

You style a label like any other element:

label {
  font-weight: bold;
  color: red;
}

I always thought this would be quite intuitive, as well. So - what are you really trying to do, the questions you ask are a sign that you have a different problem, actually.

Tomalak
Hi,Well, the problem is - i'm setting label{ min-height: 30px;} and the height is not changed.The element has no other label styles applied to it.
Mallika Iyer
@Mallika: `min-height` is not honored by all browsers, not in all rendering modes (i.e. quirks mode/standards mode - google "The Doctype Switch" to find out more) and AFAIK not for all element types (inline/block level elements). Recommended reading: http://www.w3.org/TR/css3-box/#min-max.
Tomalak
A: 

The for attribute is the input/textarea/select that the label refers to.

You can still assign an id to the label:

<label id="myLabel" for="deletetxt">Delete This Text</label>

You can also wrap the input/textarea/select with the label in order to associate them without the for attribute.

<label id="myLabel">Delete This Text <input ... /></label>
ktr
A: 

Two question, two answers:

  1. What is the 'for' attribute here?

    It's here to tell the ID of the <input> element that label refers to. Some browsers will use it to set focus on that <input> element when user clicks on that <LABEL>

  2. how do i set css for this element?

    A. If you want to CSS all label elements :

      label {
         /* your styles */
      }

B. If you want to label that element, just use IDs or classnames as you usually do.

Alain Saint-Etienne