Bug Tracker

Opened 9 years ago

Closed 8 years ago

#6133 closed bug (fixed)

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

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 (1)

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

Download all attachments as: .zip

Change History (8)

Changed 9 years ago by yurgon

HTML demo for #6133

comment:1 Changed 9 years ago by miketaylr

Milestone: 1.4.21.4.4
Priority: undecided
Status: newopen

comment:2 Changed 9 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 9 years ago by miketaylr

Milestone: 1.4.41.5
Priority: undecidedlow

comment:4 Changed 8 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 8 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 8 years ago by anonymous

:checkbox:checked also works as a workaround

eg.

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

comment:7 Changed 8 years ago by danheberden

Milestone: 1.next
Resolution: fixed
Status: openclosed

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

Note: See TracTickets for help on using tickets.