javascript - Change current element background in jQuery -
<label class="default" for="checkbox1"><input id="checkbox1" name="checkbox1" type="checkbox" style="display:none" /> text</label><br /> <label class="default" for="checkbox2"><input id="checkbox2" name="checkbox2" type="checkbox" style="display:none" /> text</label><br /> <label class="default" for="checkbox3"><input id="checkbox3" name="checkbox3" type="checkbox" style="display:none" /> text</label><br />
how should change clicked checkbox's label background color using jquery? example when second checkbox checked it's style should changed "checked":
<label class="checked" for="checkbox2"><input id="checkbox2" name="checkbox2" type="checkbox" style="display:none" /> text</label><br />
there checkbox selector in jquery, using that, assign click function grab parent "label" element , toggle css class "checked". add class , remove class depending on state of checkbox.
$("input:checkbox").click(function() { $(this).parent("label").toggleclass("checked");
also, have more luck css class names if do:
<label class="checked" for="checkbox2"><input id="checkbox2" name="checkbox2" type="checkbox" style="display:none" /> text</label><br />
instead of did above. ;)
Comments
Post a Comment