What wrong with the my code. When I click on the checkbox, nothing happen
$(document).ready(function(){
$('input:checkbox[name=drawingNo]').click(function(){alert('I am here');});
});
...
<body>
<form>
<input type="checkbox" name="drawingNo" value="1"> 1 <br>
<input type="checkbox" name="drawingNo" value="2"> 2 <br>
<input type="checkbox" name="drawingNo" value="3"> 3 <br>
<input type="checkbox" name="drawingNo" value="4"> 4 <br>
</form>
</body>
EDIT: The above code worked fine. What happen to me is that, the tag <input type="checkbox">
are generated by some other script, so when document.ready() fire up, it cant register click event to checkbox, since these checkbox are not really there yet. So to fixed it: change .click()
into .live('click', function(){...})