The title should be clear
views:
1736answers:
4
+1
A:
use the click event for best compatibility with MSIE
$(document).ready(function() {
$("input[type=checkbox]").click(function() {
alert("state changed");
});
});
Ty W
2009-09-21 15:48:23
How to judge if it's checked on or not?
Shore
2009-09-21 15:50:06
I need to know whether a click mean to check or uncheck it.
Shore
2009-09-21 15:50:56
you can then use $(this).is(':checked') to test the state of the just-clicked item
Ty W
2009-09-21 15:52:23
+2
A:
<input type="checkbox" id="something" />
$("#something").click( function(){
if( $(this).is(':checked') ) alert("checked");
});
marcgg
2009-09-21 15:50:11
document.getElementById('something').checked works,why $('#something').checked not work?
Shore
2009-09-21 15:52:45
Your code is missing a paran, and really should use the jQuery way of getting the check state.
Pete Michaud
2009-09-21 15:53:16
Because $('#something') returns a jQuery object not an ElementNode
Dmitri Farkov
2009-09-21 15:53:45
Shore: the reason getElementById works is that it returns a DOM element, whereas the $ jQuery function returns a jQuery object. The jQuery object has the DOM element as a property, but it is not, itself, a DOM object.
Pete Michaud
2009-09-21 15:54:23
this.checked should work... try making an alert(this) an check that you have the correct element.
marcgg
2009-09-21 16:17:27