]> source.dussan.org Git - jquery.git/commitdiff
Fix #2184 by using the jQuery.clean() function instead of a direct innerHTML assignme...
authorDavid Serduke <davidserduke@gmail.com>
Wed, 23 Jan 2008 03:54:23 +0000 (03:54 +0000)
committerDavid Serduke <davidserduke@gmail.com>
Wed, 23 Jan 2008 03:54:23 +0000 (03:54 +0000)
src/core.js
test/unit/core.js

index b90427b4da6f0fade5406a994a90cfa57d04093d..4cb0a22fe9402e1d402ef440b316d5ec7ec46e86 100644 (file)
@@ -303,11 +303,9 @@ jQuery.fn = jQuery.prototype = {
                                // as properties will not be copied (such as the
                                // the name attribute on an input).
                                var clone = this.cloneNode(true),
-                                       container = document.createElement("div"),
-                                       container2 = document.createElement("div");
+                                       container = document.createElement("div");
                                container.appendChild(clone);
-                               container2.innerHTML = container.innerHTML;
-                               return container2.firstChild;
+                               return jQuery.clean([container.innerHTML])[0];
                        } else
                                return this.cloneNode(true);
                });
index a5a59c3a1c0f4de05f654a214bb0ab90f844cb8a..7b0aad4ed2cc085c4fc81d3e3c694adade47cebf 100644 (file)
@@ -955,11 +955,23 @@ test("find(String)", function() {
 });
 
 test("clone()", function() {
-       expect(4);
+       expect(20);
        ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
        var clone = $('#yahoo').clone();
        ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
        ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
+
+       var cloneTags = [ 
+               "<table/>", "<tr/>", "<td/>", "<div/>", 
+               "<button/>", "<ul/>", "<ol/>", "<li/>",
+               "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>",
+               "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>"
+       ];
+       for (var i = 0; i < cloneTags.length; i++) {
+               var j = $(cloneTags[i]);
+               equals( j[0].tagName, j.clone()[0].tagName, 'Clone a &lt;' + cloneTags[i].substring(1));
+       }
+
        // using contents will get comments regular, text, and comment nodes
        var cl = $("#nonnodes").contents().clone();
        ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );