Skip to main content

Bug Tracker

Side navigation

#3879 closed bug (fixed)

Opened January 15, 2009 08:09PM UTC

Closed January 10, 2011 12:41AM UTC

appending or cloning a checked checkbox or radio button doesn't maintain the default state

Reported by: Pyro979 Owned by: snover
Priority: blocker Milestone: 1.5
Component: manipulation Version: 1.4.4
Keywords: append checked selected defaultValue defaultSelected defaultChecked Cc:
Blocked by: Blocking:
Description

This looks like a similar bug to #769, but I am experiencing this in IE7.

var check=$(document.createElement("input")).attr("type","checkbox");

check.attr("checked",true);

$("#id_main1").append(check);

The appended checkbox is no longer checked. There is an obvious workaround I can (and did) write meanwhile. But this is a pretty serious bug in my opinion.

Attachments (1)
  • test.html (0.5 KB) - added by Pyro979 January 16, 2009 12:15AM UTC.

    test case

Change History (33)

Changed January 15, 2009 09:47PM UTC by rightwildman comment:1

check.attr("checked", true) should not work at all because it is check.attr("checked", "checked") see W3C XHTML

Changed January 16, 2009 12:16AM UTC by Pyro979 comment:2

Updated the test case, bug still applies.

Changed January 17, 2009 10:36PM UTC by john comment:3

milestone: → 1.3.1
owner: → john

Is this a bug that's new in jQuery 1.3 or did it also exist in jQuery 1.2.6?

Changed January 18, 2009 07:20PM UTC by Pyro979 comment:4

It exists in 1.2.6 as well.

Changed January 31, 2009 03:58AM UTC by dmethvin comment:5

This is an old bug with IE6/7 appendChild, it clears the checked state of a checkbox. I thought there was a ticket related to the same issue with

.clone()
but I can't find it.

Changed January 06, 2010 12:20AM UTC by dmethvin comment:6

See also #5758, which shows a similar problem with radios.

Changed March 01, 2010 11:09PM UTC by icfantv comment:7

We're running in to this issue as well. Anyone know the status of fixing this? In the interim, we can set the checked state as part of the HTML construction, i.e. $('<input type="checkbox" checked="checked"/>') as a workaround.

While @Wildman may be correct re the spec, even IE6 supports using boolean flags with the .attr(...) function. That is to say, once the checkbox is added to the DOM, <obj>.attr('checked', true) works as expected. However, as noted in the bug, prior to adding to the DOM, the attr(...) function does not work - even when chained at the end of the append() function.

Changed June 15, 2010 01:11AM UTC by dmethvin comment:8

Per #6377, also happens with radio elements.

Changed June 16, 2010 03:13AM UTC by dmethvin comment:9

component: coremanipulation

Changed November 03, 2010 10:00PM UTC by boushley comment:10

Created a jsfiddle testcase http://jsfiddle.net/boushley/R3Wxx/ is running against 1.3.2 and http://jsfiddle.net/boushley/R3Wxx/1/ is running against 0 GIT. I can reproduce it from IE 7.

Changed November 04, 2010 10:53PM UTC by rwaldron comment:11

status: newopen

Tested and passing in:

  • FF3.0.12,3.6.11,4b6
  • Chrome 5,6,7,8
  • Safari 5
  • IE 6,7,8
  • Opera 10.60

http://jsfiddle.net/rwaldron/nypNd/5/

Changed November 04, 2010 11:17PM UTC by rwaldron comment:12

resolution: → worksforme
status: openclosed

Per addyosmani request, a third method:

http://jsfiddle.net/rwaldron/nypNd/7/

Changed November 04, 2010 11:37PM UTC by rwaldron comment:13

Changed November 04, 2010 11:43PM UTC by rwaldron comment:14

milestone: 1.3.1
resolution: worksforme
status: closedreopened

Changed November 04, 2010 11:44PM UTC by rwaldron comment:15

resolution: → wontfix
status: reopenedclosed

To clarify, my cases are meant to show proven, tested workaround to this unfixable, unsolvable problem.

Changed November 04, 2010 11:45PM UTC by rwaldron comment:16

resolution: wontfix
status: closedreopened

Changed November 19, 2010 03:56AM UTC by snover comment:17

#5758 is a duplicate of this ticket.

Changed November 19, 2010 03:57AM UTC by snover comment:18

summary: appending a checked checkbox doesn't maintain the cheked stateappending a checked checkbox or radio button doesn't maintain the checked state

Changed November 19, 2010 08:11AM UTC by snover comment:19

#6486 is a duplicate of this ticket.

Changed November 20, 2010 09:34PM UTC by snover comment:20

#3704 is a duplicate of this ticket.

Changed November 20, 2010 09:35PM UTC by snover comment:21

keywords: append checkboxappend checked selected defaultValue defaultSelected defaultChecked
summary: appending a checked checkbox or radio button doesn't maintain the checked stateappending or cloning a checked checkbox or radio button doesn't maintain the default state

Changed November 21, 2010 10:48PM UTC by AP Erebus comment:22

I can confirm that this is still an issue in 1.4.2, and assuming that it's still open, in 1.4.3+.

The workaround suggested by icfantv still works.

Changed November 22, 2010 05:52AM UTC by snover comment:23

priority: majorlow
resolution: → patchwelcome
status: reopenedclosed
version: 1.31.4.4

I don’t know if there is really anything that can be done about this in a way that is satisfactory; if someone wants to try their hand at a patch, we would be happy to review it.

Changed November 30, 2010 04:34AM UTC by julien comment:24

I wish this ticket weren't closed. I've actually noticed the exact same issue in Chrome.

Changed November 30, 2010 03:00PM UTC by rwaldron comment:25

Replying to [comment:24 julien]:

I wish this ticket weren't closed. I've actually noticed the exact same issue in Chrome.

As snover mentioned, patches are welcome.

Changed December 07, 2010 09:37PM UTC by fletch@fletchowns.net comment:26

Didn't see a test case using clone: http://www.jsfiddle.net/fletch/CLq3P/

Works fine in Firefox 3.6 and Chrome 8, does not work in IE8.

Changed December 30, 2010 05:46AM UTC by snover comment:27

milestone: → 1.5
resolution: patchwelcome
status: closedreopened

Changed December 30, 2010 05:46AM UTC by snover comment:28

owner: johnsnover
status: reopenedassigned

Changed January 07, 2011 08:25PM UTC by Pyro979 comment:29

Let me say right away that I'm not sure that I'm doing this correctly, and whether or not this is the "proper" way to fix this bug. But this seems to work. I can probably benefit from some more optimization

https://github.com/Pyro979/jquery

Changed January 08, 2011 10:26PM UTC by Pyro979 comment:30

Just added a jQuery.support.checkboxAppendPermanence check into support.js. This should improve performance since we won't need to do any of this "checked" re-assigning when it works fine. Don't know if I put it into the right spot.

Changed January 08, 2011 10:29PM UTC by snover comment:31

Pyro979, there is already an outstanding open pull request for this issue; you don’t need to write code to fix this ticket.

Changed January 08, 2011 10:29PM UTC by snover comment:32

priority: lowblocker

Changed January 10, 2011 12:41AM UTC by Colin Snover comment:33

resolution: → fixed
status: assignedclosed

Ensure that buildFragment clones elements properly in all browsers. Fixes #3879, #6655. Also improves form element clone tests and fixes bugs in $.fn.clone exposed by these new test cases related to the values of checkboxes and radio buttons in IE.

Changeset: b14f02899e74c429effadd88527ffde17650149a