Bug Tracker

Modify

Ticket #5727 (closed bug: duplicate)

Opened 3 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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()">&lt;-- 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

comment:1 Changed 3 years ago by angelbob

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()">&lt;-- 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();
}

comment:2 Changed 3 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to duplicate

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.