javascript - Tracking checkbox event using jquery -


i have following code:

$("#chkbx_first").change(function () { if ($(this).attr("checked")) {     alert("check box selected"); //do when checked } else {     alert("check box unselected"); //do when cleared } 

the problem despite on checkbox stste second allert appears time - "check box unselected". why first alert doesn't appear ?

is there approaches track check event? thanx.

try if (this.checked) or use .prop()

$("#chkbx_first").change(function () {     if (this.checked) { // or if($(this).prop("checked")){         alert("check box selected"); //do when checked     } else {         alert("check box unselected"); //do when cleared     } } 

read attributes vs. properties


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -