1

I am trying to get the label for a checkbox using jQuery. Here is my HTML:

<div class="checkbox">
    <label><input type="checkbox" name="cb_type[]" value="sold" >Sold</label>
</div>

I have tried:

$("label[for=:checkbox[value='sold']]");

I know that this works:

$(":checkbox[value='sold']");

Any ideas on how I can get this work?

MoreScratch
  • 2,933
  • 6
  • 34
  • 65

2 Answers2

1

You basically had it. Just needed the parent.

console.log($(":checkbox[value='sold']").parent());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div class="checkbox">
    <label><input type="checkbox" name="cb_type[]" value="sold" >Sold</label>
</div>
Doug F
  • 894
  • 2
  • 13
  • 18
0

Please, refer this post

jQuery selector for the label of a checkbox label-of-a-checkbox

you have to have a

your label tag doesnt have explicit for attribute but use the nested tags.

user_D_A__
  • 460
  • 2
  • 6
  • 14