Ran into an interesting bug this morning with jQuery 1.2.2. After testing a simple working jQuery function in FF, I then tested in IE and found that it didn’t work in IE. The jQuery code is fairly straightforward, so I was extremely perplexed.
$("#existingFacilities").dblclick(function() {
$("#selectedFacilities").append($("#existingFacilities option:selected").clone());
});
All this does is clone an option from one select box and append it to another when it is double-clicked. After a few minutes of debugging, I removed the clone() function and it worked. For some reason, IE won’t work with cloned objects in jQuery. So instead of having a copy of the same option in two select boxes, it’s removed from the first and added to the second.
Here’s my workaround.
$("#existingFacilities").dblclick(function() {
var selectedOption = $("#existingFacilities option:selected");
var newOption = new Option($(selectedOption).text(), $(selectedOption).val());
var ops = $("#selectedFacilities").attr("options");
if( typeof(ops) != "undefined" )
ops[ops.length] = newOption;
else
$("#selectedFacilities").append(selectedOption.clone());
});
Hope this helps someone.
2 Responses for "jQuery clone() bug in Internet Explorer"
Steve,
This should be resolved in the latest SVN of jQuery and we plan on releasing 1.2.3 soon which fixes a couple of issues (like this one) with 1.2.2.
Steve,
I was mistaken… I thought the patch had already landed in the trunk. However, it hasn’t been committed yet. You can find the patch that should resolve the issue you are seeing here: http://dev.jquery.com/ticket/2184
The ticket doesn’t describe your same scenario but it should still apply.
Leave a reply