Bug Tracker

Modify

Ticket #10827 (closed bug: duplicate)

Opened 2 years ago

Last modified 2 years ago

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

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

comment:1 Changed 2 years ago by timmywil

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

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 2 years ago by dmethvin

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

comment:3 Changed 2 years ago by dmethvin

Duplicate of #3827.

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.