jQuery: The Write Less, Do More JavaScript Library

Changeset 4206

Show
Ignore:
Timestamp:
12/17/07 16:54:44 (8 months ago)
Author:
davidserduke
Message:

Fixed #2062 by adding a check to see if the selector is array-like in .not() before testing it as an array. Otherwise it does a straight comparison during the filter test.

Location:
trunk/jquery
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r4196 r4206  
    354354 
    355355        return this.filter(function() { 
    356             return jQuery.inArray( this, selector ) < 0; 
     356            // check to see if the selector is array-like otherwise assume it is just a DOM element 
     357            return ( selector.length && selector[selector.length - 1] !== undefined ) 
     358                ? jQuery.inArray( this, selector ) < 0 
     359                : this != selector; 
    357360        }); 
    358361    }, 
  • trunk/jquery/test/unit/core.js

    r4196 r4206  
    10591059 
    10601060test("not()", function() { 
    1061     expect(5); 
     1061    expect(7); 
    10621062    ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" ); 
     1063    ok( $("#main > p#ap > a").not(document.getElementById("google")).length == 2, "not(DOMElement)" ); 
    10631064    isSet( $("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); 
    10641065    isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); 
    10651066    isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); 
     1067    ok( $("p").not(document.getElementsByTagName("p")).length == 0, "not(Array-like DOM collection)" ); 
    10661068    isSet( $("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d" ), "not('complex selector')"); 
    10671069});