Skip to main content

Bug Tracker

Side navigation

#5727 closed bug (duplicate)

Opened December 29, 2009 08:10PM UTC

Closed December 30, 2009 04:33AM UTC

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>

Attachments (0)
Change History (2)

Changed December 29, 2009 08:11PM UTC by angelbob comment:1

Sorry, here's the same code with better formatting:

<input type="checkbox" id="bob">

<p id="boxtext">Never been clicked</p> 
 
<p id="counter">Counter goes here</p> 
 
<p> Inert placeholder. </p> 
 
<input type="checkbox" onClick="clickTrigger()"><-- Click the box</p> 
 
<script type="text/javascript"> 
//<![CDATA[
 
 
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();
}

Changed December 30, 2009 04:33AM UTC by dmethvin comment:2

resolution: → duplicate
status: newclosed

This is a duplicate of #3827, see the discussion there.