jeudi 7 juillet 2016

add highlight class to the label of a checked check box via a button

I have checked all over stack overflow, but they're not exactly what I need. I have checkboxes with associated labels

<p>
  <input type="checkbox" name="animals" value="dog" id="dg" />
  <label for="dg">Dog</label>
</p>
<p>
  <input type="checkbox" name="animals" value="cat" id="ct" />
  <label for="ct">Cats</label></p>
<p>

<p><input type="button" id='bt' value="Record" /></p> 

There is also a button, when the button is clicked, if the checkbox is checked, the label associated with it has a highlight class added to the label. I already have the highlight class written I am just having trouble applying it using the addClass method.

I have:

         $(':checkbox:checked').addClass('highlight');

but it does nothing

Aucun commentaire:

Enregistrer un commentaire