javascript - Determining whenever user checks or unchecks a checkbox -


here code:

$(document).ready(function () {     $("input[type='checkbox'][name='mycheckboxname']").change(function () {         if ($(this).checked == true) {             //do (script 1)         }         else {             //do else (script 2)         }     }) }); 

what want accomplish have 2 scripts running depening whenever user checks or unchecks "mycheckboxname" checkbox. problem above code script 2 run looks if $(this).checked false if user checks checkbox. using $(this) wrong way?

checked dom property of element, $(this) returns jquery object.

you use dom property:

if (this.checked) 

there's no reason wrap this in jquery instance that. mean, can:

if ($(this).prop("checked")) 

...but doesn't useful on top of this.checked.


side note:

if (someboolean == true) 

is roundabout way of writing

if (someboolean) 

i mean, why stop there? why not

if ((someboolean == true) == true) 

or

if (((someboolean == true) == true) == true) 

or... ;-)


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -