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

This is some different different method to do the same thinkthing:

$(document).ready(function (){ 

  
   $('#isAgeSelected').click(function() {
        //  $("#txtAge").toggle(this.checked); 

  
   
     // usingUsing a pure CSS selector 
  
       if ($(this.checked)) { 
  
           alert('on check 1'); 
  
       }; 

  
   
     // usingUsing jQuery's is() method 
  
       if ($(this).is(':checked')) { 
  
           alert('on checked 2'); 
  
       }; 

  
   
     //  // usingUsing jQuery's filter() method 
  
       if ($(this).filter(':checked')) { 
  
           alert('on checked 3');  
   };  
    };
    });
});
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<input type="checkbox" id="isAgeSelected"/>
<div id="txtAge" style="display:none">Age is something</div>

This is some different different method to do same think

$(document).ready(function (){
  
 $('#isAgeSelected').click(function() {
  //  $("#txtAge").toggle(this.checked);
  
   
  // using a pure CSS selector  
    if ($(this.checked)) {  
       alert('on check 1');  
    };  
   
    // using jQuery's is() method  
    if ($(this).is(':checked')) {  
      alert('on checked 2');  
    };  
   
  //  // using jQuery's filter() method  
    if ($(this).filter(':checked')) {  
       alert('on checked 3');  
   };  
    
    });
});
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<input type="checkbox" id="isAgeSelected"/>
<div id="txtAge" style="display:none">Age is something</div>

This is some different method to do the same thing:

$(document).ready(function (){ 

    $('#isAgeSelected').click(function() {
        // $("#txtAge").toggle(this.checked); 

        // Using a pure CSS selector 
        if ($(this.checked)) { 
            alert('on check 1'); 
        }; 

        // Using jQuery's is() method 
        if ($(this).is(':checked')) { 
            alert('on checked 2'); 
        }; 

        //  // Using jQuery's filter() method 
        if ($(this).filter(':checked')) { 
            alert('on checked 3');
        };
    });
});
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<input type="checkbox" id="isAgeSelected"/>
<div id="txtAge" style="display:none">Age is something</div>

Source Link
Sangeet Shah
  • 3.1k
  • 3
  • 23
  • 25

This is some different different method to do same think

$(document).ready(function (){
  
$('#isAgeSelected').click(function() {
  //  $("#txtAge").toggle(this.checked);
  
  
 // using a pure CSS selector  
   if ($(this.checked)) {  
      alert('on check 1');  
   };  
  
   // using jQuery's is() method  
   if ($(this).is(':checked')) {  
     alert('on checked 2');  
   };  
  
 //  // using jQuery's filter() method  
   if ($(this).filter(':checked')) {  
      alert('on checked 3');  
   };  
   
    });
});
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<input type="checkbox" id="isAgeSelected"/>
<div id="txtAge" style="display:none">Age is something</div>

Post Made Community Wiki by Sangeet Shah