This script causes the alert to show regardless of whether the checkbox is being ticked on or off. How can it only show when the tick box is being clicked on?
$("#x").click(function() {
alert("Ticker is has been clicked on!");
});
This script causes the alert to show regardless of whether the checkbox is being ticked on or off. How can it only show when the tick box is being clicked on?
$("#x").click(function() {
alert("Ticker is has been clicked on!");
});
A simple if conditional will do the trick for you:
$("#x").click(function(){
if($(this).is(":checked")) {
alert("Ticker is has been clicked on!");
}
});
Check out some reading on the .is() method and :checked selector within jQuery.