javascript - Checkbox not getting clicked on clicking label -
the set have pretty straight forward , know what's causing issue me.
here fiddle of work: https://jsfiddle.net/ppw9b34u/
its collection of labels within form. when click on 1 of labels, corresponding input gets checked. however, if click @ little faster rate. there high possibility end changing colors of few labels without checking input box.
what observe if click drag little on label. colors red , not checks checkbox. have no idea such scenarios. please help
i attaching code below
html:
<div class="diag_options clearfix"> <form action="#" class="diag_options_form pap_answer"> <p> <input type="checkbox" data-value="6" id="test6"> <label for="test6">cardio vascular disease</label> </p> <p> <input type="checkbox" data-value="7" id="test7"> <label for="test7" class="">diabetes type 1</label> </p> <p> <input type="checkbox" data-value="8" id="test8"> <label for="test8" class="">diabetes type 2</label> </p> <p> <input type="checkbox" data-value="9" id="test9"> <label for="test9" class="">hypertension</label> </p> <p> <input type="checkbox" data-value="10" id="test10"> <label for="test10" class="">arthritis</label> </p> <p> <input type="checkbox" data-value="11" id="test11"> <label for="test11" class="">cancer</label> </p> <p> <input type="checkbox" data-value="12" id="test12"> <label for="test12">depression</label> </p> <p> <input type="checkbox" data-value="13" id="test13"> <label for="test13" class="">high cholesterol</label> </p> <p> <input type="checkbox" data-value="190" id="test190"> <label for="test190" class="">anemia</label> </p> <p> <input type="checkbox" data-value="179" id="test179"> <label for="test179" class="">none of above</label> </p> </form> </div>
javascript:
$(".diag_options p label").on("click",function(){ if($(this).hasclass("none_opt")){ $('.diag_options p label').removeclass("check"); $(this).addclass("check"); } else if($(this).hasclass("check")){ $(this).removeclass("check"); } else{ $('.diag_options ul p label').removeclass("check"); $(this).addclass("check"); } });
css:
input[type="radio"], input[type="checkbox"] { line-height: normal; margin: 4px 0 0; } input[type="checkbox"], input[type="radio"] { box-sizing: border-box; padding: 0; } input, button, select, textarea { font-family: inherit; font-size: inherit; line-height: inherit; } .diag_options p { float: left; margin: 1%; width: 14.66%; } .diag_options p label { border: 1px solid #ccc; color: #999; display: block; font-family: roboto-regular; font-size: 0.8rem; font-weight: 400; height: auto; line-height: 1; margin: 0; min-height: 125px; padding: 44px 10px 0; position: relative; text-align: center; } .pap_answer label { -moz-user-select: none; } .diag_options p label::before { content: ""; display: none; } .check { background: #f98586 none repeat scroll 0 0; border: 1px solid #fff !important; color: #fff !important; } .check::after { background: rgba(0, 0, 0, 0) url("/assets/paps_images/sprite_icon.svg") no-repeat scroll -110px 0 / auto 100%; content: ""; height: 22px; position: absolute; right: 0; top: 0; width: 22px; }
if rely on checkbox being checked, instead of clicking label, avoid such problems
$(".diag_options p input").on("change",function(){ $(this).next().toggleclass('check', this.checked); });
Comments
Post a Comment