Search code examples
jquerycheckboxlabelskip

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


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


Solution

  • 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