Opened 13 years ago
Closed 13 years ago
#5727 closed bug (duplicate)
Checkboxes "is(':checked')" is opposite for programmatic click() than user click
Reported by: | angelbob | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | unfiled | Version: | 1.3.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
The predicate is(':checked') returns the correct checked-ness when called from a click() callback if the user clicks on the checkbox. Makes sense.
However, if $("#checkbox_id").click() is called on the checkbox, the same predicate returns the opposite.
For a simple example, see the HTML below. When you click on the first checkbox, you should see the correct "box is checked" or "box isn't checked" paragraph. When you click on the second checkbox, which calls .click() on the first checkbox, you'll see the incorrect one.
<input type="checkbox" id="bob">
<p id="boxtext">Never been clicked</p>
<p id="counter">Counter goes here</p>
<input type="checkbox" onClick="clickTrigger()"><-- Click the box</p> <script type="text/javascript"> var counter = 0; $$("#bob").click(function() {
if($$("#bob").is(':checked')) {
$$("#boxtext").html("Box is checked")
} else {
$$("#boxtext").html("Box isn't checked")
} ++counter; $$("#counter").html("Counter: " + counter);
}); function clickTrigger() {
$$("#bob").click();
} </script>
Change History (2)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
Resolution: | → duplicate |
---|---|
Status: | new → closed |
This is a duplicate of #3827, see the discussion there.
Sorry, here's the same code with better formatting: