javascript - adding click event to class with jQuery -


i found found several question's answers similar this, tried of them, no luck. may scenario different, want make other checkbox disable when of them clicked. if 1 clicked second go disabled.

edit:

i have 2 checkboxes i.e; chk1 , chk2. if chk1 checked chk2 become disable, if chk2 checked chk1 become disable

html

<tr class="cart-item-row"> <td class="remove-from-cart"> <label class="td-title">remove:</label>      <input type="checkbox" name="removefromcart" value="4392" tabindex="15" class="class2"> </td> <td class="add-to-cart"> <label class="td-title">buy now:</label>     <input type="checkbox" name="addtocart" value="4392" tabindex="16" class="class2"> </td>                                                                                                                         </tr> 

js

<script>     $(function () { // adding class checkbox through js         $('.cart-item-row > td > input[type="checkbox"]').addclass("class2");     }); </script> <script>     //$('input[class^="class"]').click(function () {  //$('.class2').unbind().click(function () {     $('.class2').click(function () {         var $this = $(this);          if ($this.is(".class2")) {             if ($this.is(":checked")) {                 $(".class2").not($this).prop({ disabled: true, checked: false });              } else {                 $(".class2").prop("disabled", false);             }         }     }); </script> 

you have missing , can place jquery within

$(document).ready(function(){ }


Comments