Bug Tracker

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#10827 closed bug (duplicate)

Triggering "click" event on a checkbox toggles the "checked" property after the handler function has run

Reported by: phistuck Owned by: phistuck
Priority: low Milestone: None
Component: event Version: 1.7.1rc1
Keywords: Cc:
Blocked by: Blocking:

Description

When a user click on a checkbox with a click listener, it first flips the "checked" state and then fires the event. When a developer initiates a click on a checkbox with jQuery, it first fires the event and then flips the "checked" state.

A complete test case (for convenience, copy the code, type (without the quotes) within the location bar "data:text/html,", paste the code and press Enter) -

<!DOCTYPE HTML>
<html>
 <head>
  <title>Test</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
  <script>
   function run()
   {
    $("#test-checkbox").click(function () { alert(this.checked); });
    $("#test-click").click(function () { $("#test-checkbox").click(); });
   }
  </script>
 </head>
 <body onload="run()">
  <input type="checkbox" id="test-checkbox"/>
  <span id="test-click">Initiate a click event</span>
 </body>
</html>

This has been like that since forever (I checked with jQuery 1.2.4, 1.3.2, 1.4, 1.7, 1.7.1rc1).

Change History (3)

comment:1 Changed 5 years ago by timmywil

  • Component changed from unfiled to event
  • Owner set to phistuck
  • Priority changed from undecided to low
  • Status changed from new to pending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

I believe the order is dependent on the browser. Which browser are you using?

comment:2 Changed 5 years ago by dmethvin

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

comment:3 Changed 5 years ago by dmethvin

Duplicate of #3827.

Note: See TracTickets for help on using tickets.