How to find checked event in a checkbox using jquery?
I am trying to execute a function on clicking a check box. For that I am using the following code but it is not working can anyone find whats the problem with this code?
$('#selectAll').click(function(){
alert("hi");
});
HTML
<th><i开发者_高级运维nput type="checkbox" name="selectl" value="ON" id="selectAll"/></th>
I tried this example below and it is working with the latest jquery version.
<script type="text/javascript">
$(document).ready(function () {
$("#chk").change(function () {
var $this = $(this);
var checked = $this.is(':checked');
if (checked) {
alert('checked');
}
});
});
</script>
<input id="chk" type="checkbox" />
$(function(){
$('#selectAll').change(function(){
alert("value changed");
});
});
See a working demo.
$('#selectAll').bind('change',function(){
alert("hi");
});
Use 'change' instead! jsFiddle
精彩评论