jQuery: The Write Less, Do More JavaScript Library

Ticket #2184: 2184.diff

File 2184.diff, 1.8 kB (added by davidserduke, 7 months ago)

possible patch

  • test/unit/core.js

     
    955955}); 
    956956 
    957957test("clone()", function() { 
    958     expect(4); 
     958    expect(20); 
    959959    ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' ); 
    960960    var clone = $('#yahoo').clone(); 
    961961    ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' ); 
    962962    ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' ); 
     963 
     964    var cloneTags = [  
     965        "<table/>", "<tr/>", "<td/>", "<div/>",  
     966        "<button/>", "<ul/>", "<ol/>", "<li/>", 
     967        "<input type='checkbox' />", "<select/>", "<option/>", "<textarea/>", 
     968        "<tbody/>", "<thead/>", "<tfoot/>", "<iframe/>" 
     969    ]; 
     970    for (var i = 0; i < cloneTags.length; i++) { 
     971        var j = $(cloneTags[i]); 
     972        equals( j[0].tagName, j.clone()[0].tagName, 'Clone a &lt;' + cloneTags[i].substring(1)); 
     973    } 
     974 
    963975    // using contents will get comments regular, text, and comment nodes 
    964976    var cl = $("#nonnodes").contents().clone(); 
    965977    ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" ); 
  • src/core.js

     
    303303                // as properties will not be copied (such as the 
    304304                // the name attribute on an input). 
    305305                var clone = this.cloneNode(true), 
    306                     container = document.createElement("div"), 
    307                     container2 = document.createElement("div"); 
     306                    container = document.createElement("div"); 
    308307                container.appendChild(clone); 
    309                 container2.innerHTML = container.innerHTML; 
    310                 return container2.firstChild; 
     308                return jQuery.clean([container.innerHTML])[0]; 
    311309            } else 
    312310                return this.cloneNode(true); 
    313311        });