Bug Tracker

Modify

Ticket #6133 (closed bug: fixed)

Opened 3 years ago

Last modified 2 years ago

:checked fails on dynamically generated checkboxes in Opera 10

Reported by: yurgon Owned by:
Priority: low Milestone: 1.next
Component: selector Version: 1.4.1
Keywords: checked opera10 Cc:
Blocking: Blocked by:

Description

In Opera 10.10, the :checked selector fails on checkboxes that are dynamically generated into the DOM by AJAX requests, document.write(), $.append() etc. The problem appears on checkboxes but not on radiobuttons. Other browsers work fine (tested in IE 6-8, Firefox 3.6, Chrome 4.0, Safari 4.0). Unfortunately, I don't have older versions of Opera available for testing. The same problem existed in jQuery 1.3.2.

The attached HTML file demonstrates the problem: the total number of :checked elements is counted. The link "Duplicate <div> with checkboxes and radiobuttons" clones the form and inserts the clone into the DOM. In Opera 10, the updated count of :checked elements is now wrong - the new checkboxes are ignored. Manually un- and then rechecking the checkboxes sets the count right.

The problem appears to be independent of the technique used to insert content into the DOM (I originally noticed it on content delivered by AJAX request).

Attachments

jquery_bug_checked_opera.html Download (1.7 KB) - added by yurgon 3 years ago.
HTML demo for #6133

Change History

Changed 3 years ago by yurgon

HTML demo for #6133

comment:1 Changed 3 years ago by miketaylr

  • Priority set to undecided
  • Status changed from new to open
  • Milestone changed from 1.4.2 to 1.4.4

comment:2 Changed 3 years ago by miketaylr

Confirmed in Opera 9.64, 10.10, 10.20, 10.50, 10.63, and 11 alpha.

Updated test case to use 1.4.3:  http://miketaylr.com/test/jquery_bug_checked_opera.htm

comment:3 Changed 3 years ago by miketaylr

  • Priority changed from undecided to low
  • Milestone changed from 1.4.4 to 1.5

comment:4 follow-up: ↓ 5 Changed 2 years ago by anonymous

Workaround: You can use .attr("checked") to find out if the checkboxes are currently checked. I added a class to my generated checkboxes to easily select them and then used a foreach loop to evaluate the checked attribute.

Example: $("input.checkboxClass").each(function() { alert($(this).attr("checked")); });

comment:5 in reply to: ↑ 4 Changed 2 years ago by yurgon

Replying to anonymous:

Workaround: You can use .attr("checked") to find out if the checkboxes are currently checked.

Confirmed, that workaround works. It's still a workaround, though. :-)

BTW, I just confirmed the Bug in Opera 11.01 (Build 1190, Win32) with the test case provided by miketaylr for jQuery 1.4.3.

comment:6 Changed 2 years ago by anonymous

:checkbox:checked also works as a workaround

eg.

$('.myClass:checked').length = 0 $('.myClass:checkbox:checked').length = 4

comment:7 Changed 2 years ago by danheberden

  • Status changed from open to closed
  • Resolution set to fixed
  • Milestone set to 1.next

 http://jsfiddle.net/danheberden/VEtms/ - works on opera 11 and 10 with jq 1.5.1

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.