Skip to main content

Bug Tracker

Side navigation

#14109 closed bug (notabug)

Opened July 06, 2013 09:11PM UTC

Closed July 07, 2013 05:05PM UTC

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

Reported by: jan.misek@rclick.cz 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>
Attachments (0)
Change History (1)

Changed July 07, 2013 05:05PM UTC by gibson042 comment:1

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)