Bug Tracker

Opened 13 years ago

Closed 13 years ago

#1866 closed bug (duplicate)

IE6, appech checkbox to div, checked attribute gone.

Reported by: zozoh Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: IE6 append checkbox Cc:
Blocked by: Blocking:

Description

Example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
    var c = $("<INPUT type=checkbox>");
	c[0].checked = true;
	$("#before").text(c[0].outerHTML);
	$("#cc").append(c);
	$("#after").text(c[0].outerHTML);
});
</script>
</head>
<body>
<div id="cc"></div>
<b>Before:</b>
<div id="before"></div>
<b>After:</b>
<div id="after"></div>
</body>
</html>

Execute result:

Before: 
<INPUT type=checkbox CHECKED>
After: 
<INPUT type=checkbox>

I try to update append code like this:


append: function() {
		return this.domManip(arguments, true, 1, function(a){
			if(jQuery.browser.msie  && 	jQuery.nodeName(a, "input") && a.type.toLowerCase()=="checkbox"){
				var checked = a.checked;
				this.appendChild( a );
				a.checked = checked;
			}else
				this.appendChild( a );
		});
	}

it worked.

Change History (3)

comment:1 Changed 13 years ago by zozoh

function "append":

append: function() {
	return this.domManip(arguments, true, 1, function(a){
		/* Special for IE */
		if(a && a.nodeType==1 && jQuery.browser.msie && jQuery.browser.version=="6.0"){
			/* store original */
			var arr = new Array();
			jQuery(a).find(":checkbox").andSelf().filter(":checkbox").each(function(){
				arr.push(this.checked);
			});
			this.appendChild( a );
			/* restore */
			if(arr.length>0){
				var jq = jQuery(a).find(":checkbox").andSelf().filter(":checkbox");
				for(var i in arr)
					jq[i].checked = arr[i];
			}
		}else{
			this.appendChild( a );
		}
	});
},

It work in most of cases.

comment:2 Changed 13 years ago by davidserduke

comment:3 Changed 13 years ago by davidserduke

Resolution: duplicate
Status: newclosed

Duplicate of #769.

Note: See TracTickets for help on using tickets.