Reputation: 23
I'm having a problem with this one:
if($("#Autotag").is(":checked"))
{
alert("Just to check if it works");
}
But it won't give me the alert dialog while it's checked! I've been looking for right answers. All the other codes I've written does work but not this one.
jsFiddle ain't giving me any hints as person told me to try... I've also been reading this How to: jQuery how to
Upvotes: 0
Views: 85
Reputation: 207557
That code will not run when the person checks the checkbox, it will just tell you the state of the checkbox at that moment in time it has run.
If you want to know when it is checked, you need to listen for the change event. The following code assumes you call this onready or after the element is added to the page.
$("#Autotag").on("change", function () {
if($(this).is(":checked")) {
alert("Just to check if it works");
}
});
Upvotes: 3
Reputation: 494
You need to be calling this inside a change event, instead of just calling it once
$("#Autotag").change(function() {
var $this = $(this);
if ( $this.is(":checked") ) {
alert("This should work for you");
}
});
Upvotes: 1