views:

54

answers:

3

How to skip one label having same class name of other in jquery

<label for="myCb1">test1</label>
<label for="myCb1">test</label>
<input type="checkbox" id="myCb1" value="1" />

when i try to invoke the label of myCb1 both are display so please help how to skip one label using jquery

+1  A: 

$('.class:first-child')

This is if they are right next to each other like you just described.

Chacha102
+1  A: 

Either give them an id to uniquely identify them, or you can use a selector such as:

$("label[for=myCb1]:eq(0)") // Only selects the first label
$("label[for=myCb1]:eq(1)") // Only selects the second label
Cide
Thanks it is working good job buddy
Senthil Kumar Bhaskaran
+1  A: 

You want to use the :eq pseudo-selector as such:

$("label[for='myCb1']:eq(1)")

:eq allows you to specify the index of the found elements that you want to return. The index is zero-based (which means that the first element will be index 0).

jQuery Docs: :eq pseudo-selector

Andrew Moore
good job thanks buddy
Senthil Kumar Bhaskaran