Bug Tracker

Opened 6 years ago

Closed 6 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:

Description

Reproduction:

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

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

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

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

   $('div.result').html(result1 + ' ' + result2)
</script>

Change History (1)

comment:1 Changed 6 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.