Skip to main content
Copy edited.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

Using the Click event handler for the checkbox property is unreliable, as the checked property can change during the execution of the event handler itself! 

Ideally, you'd want to put your code into a change event handler such as it is fired every time the value of the check box is changed  (independent of how it's done so).

$('#isAgeSelected').bind('change', function () {
        
   if ($(this).is(':checked'))
     $("#txtAge").show();
   else
     $("#txtAge").hide();
 
});

Using the Click event handler for the checkbox property is unreliable, as the checked property can change during the execution of the event handler itself! Ideally, you'd want to put your code into a change event handler such as it is fired every time the value of the check box is changed(independent of how it's done so).

$('#isAgeSelected').bind('change', function () {
        
   if ($(this).is(':checked'))
     $("#txtAge").show();
   else
     $("#txtAge").hide();
 
});

Using the Click event handler for the checkbox property is unreliable, as the checked property can change during the execution of the event handler itself! 

Ideally, you'd want to put your code into a change event handler such as it is fired every time the value of the check box is changed  (independent of how it's done so).

$('#isAgeSelected').bind('change', function () {

   if ($(this).is(':checked'))
     $("#txtAge").show();
   else
     $("#txtAge").hide();
});
Post Made Community Wiki by Udit Bhardwaj
Source Link
arviman
  • 5.2k
  • 43
  • 48

Using the Click event handler for the checkbox property is unreliable, as the checked property can change during the execution of the event handler itself! Ideally, you'd want to put your code into a change event handler such as it is fired every time the value of the check box is changed(independent of how it's done so).

$('#isAgeSelected').bind('change', function () {
        
   if ($(this).is(':checked'))
     $("#txtAge").show();
   else
     $("#txtAge").hide();

});