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

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -