Skip to main content

Bug Tracker

Side navigation

#10827 closed bug (duplicate)

Opened November 18, 2011 02:13PM UTC

Closed November 18, 2011 03:19PM UTC

Last modified November 18, 2011 03:19PM UTC

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).

Attachments (0)
Change History (3)

Changed November 18, 2011 03:14PM UTC by timmywil comment:1

component: unfiledevent
owner: → phistuck
priority: undecidedlow
status: newpending

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?

Changed November 18, 2011 03:19PM UTC by dmethvin comment:2

resolution: → duplicate
status: pendingclosed

Changed November 18, 2011 03:19PM UTC by dmethvin comment:3

Duplicate of #3827.