Skip to main content

Bug Tracker

Side navigation

#6133 closed bug (fixed)

Opened February 20, 2010 04:35PM UTC

Closed March 30, 2011 08:37PM UTC

: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)
Change History (7)

Changed October 21, 2010 06:52PM UTC by miketaylr comment:1

milestone: 1.4.21.4.4
priority: → undecided
status: newopen

Changed October 21, 2010 06:53PM UTC by miketaylr comment:2

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

Changed October 21, 2010 06:59PM UTC by miketaylr comment:3

milestone: 1.4.41.5
priority: undecidedlow

Changed February 22, 2011 12:28AM UTC by anonymous comment:4

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"));

});

Changed February 22, 2011 01:12AM UTC by yurgon comment:5

Replying to [comment:4 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.

Changed March 01, 2011 10:55PM UTC by anonymous comment:6

:checkbox:checked also works as a workaround

eg.

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

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

Changed March 30, 2011 08:37PM UTC by danheberden comment:7

milestone: → 1.next
resolution: → fixed
status: openclosed

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