Added a fix, and tests, for appending empty sets of elements/strings.
authorJohn Resig <jeresig@gmail.com>
Sun, 14 Jan 2007 19:30:40 +0000 (19:30 +0000)
committerJohn Resig <jeresig@gmail.com>
Sun, 14 Jan 2007 19:30:40 +0000 (19:30 +0000)
src/jquery/coreTest.js
src/jquery/jquery.js

index ccd84f7..f736d4d 100644 (file)
@@ -192,7 +192,7 @@ test("wrap(String|Element)", function() {
 });\r
 \r
 test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {\r
-       expect(5);\r
+       expect(9);\r
        var defaultText = 'Try them out:'\r
        var result = $('#first').append('<b>buga</b>');\r
        ok( result.text() == defaultText + 'buga', 'Check if text appending works' );\r
@@ -212,6 +212,15 @@ test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
        expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";\r
        $('#sap').append($("#first, #yahoo"));\r
        ok( expected == $('#sap').text(), "Check for appending of jQuery object" );\r
+\r
+       reset();\r
+       $("#sap").append( 5 );\r
+       ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );\r
+\r
+       reset();\r
+       ok( $("#sap").append([]), "Check for appending an empty array." );\r
+       ok( $("#sap").append(""), "Check for appending an empty string." );\r
+       ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );\r
 });\r
 \r
 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {\r
index b010387..83711de 100644 (file)
@@ -1443,6 +1443,9 @@ jQuery.extend({
                                
                                arg = div.childNodes;
                        }
+
+                       if ( arg.length === 0 )
+                               continue;
                        
                        if ( arg[0] == undefined )
                                r.push( arg );