Bug Tracker

Opened 10 years ago

Closed 10 years ago

#14109 closed bug (notabug)

Selector ":not" does not behave same for selection by .class and by element names (tagName)

Reported by: jan.misek@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:



JSFiddle: http://jsfiddle.net/udGb2/1/

<div class="sandbox">
    <div class="test" >
        <div class="test" >
            <div class="test" >
                <div class="test">

<div class="result">
  Result of following js code goes here. Result should be "1 1" but it is "1 0" 

   var result1 = ($('.sandbox').find('.test:not(.test .test)').length);
   var result2 = ($('.sandbox').find('div:not(div div)').length);

   $('div.result').html(result1 + ' ' + result2)

Change History (1)

comment:1 Changed 10 years ago by gibson042

Resolution: notabug
Status: newclosed

Much like the recent #14043 (which tripped me up as well, at first glance), this is not a bug. The expressions are interpreted as follows:

  • $('.sandbox').find('.test:not(.test .test)'): descendants (of elements with class "sandbox") that have class "test" and are not descended from other elements with class "test" (equivalent to $('.sandbox').find('.test:not(.test *)'); matches the first sandbox child)
  • $('.sandbox').find('div:not(div div)'): div descendants (of elements with class "sandbox") that are not descended from other divs (equivalent to $('.sandbox').find('div:not(div *)'); matches nothing since the sandbox is itself a div)
Note: See TracTickets for help on using tickets.