I'm trying hook up a checkbox check event with additional events (such as a dialog display). However, I can't seem to get the click event working when I'm testing my html file in a browser. It does work in JSFiddle, though, which is very strange.
My HTML:
<label><input type="checkbox" name="checkbox-0" id="myCheckbox" /> Completed </label>
My JavaScript:
var countChecked = function() {
if ($("#myCheckbox").is(":checked"))
{
alert('checked!');
}
};
$( "input[type=checkbox]" ).on( "click", countChecked );
The html file that I wrote:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<script>
// On clicking of the completed checkbox, we want to pop up a dialog for confirmation.
var checkboxClicked = function() {
if ($("#myCheckbox").is(":checked")) {
alert('checked!');
console.log('checked!')
}
};
$( "input[type=checkbox]" ).on( "click", checkboxClicked );
</script>
</head>
<body>
<label><input type="checkbox" name="checkbox-0" id="myCheckbox" /> Completed </label>
</body>
</html>