Skip to main content

Bug Tracker

Side navigation

#4344 closed bug (wontfix)

Opened March 13, 2009 04:40AM UTC

Closed July 11, 2011 06:43PM UTC

~, > selector with descendant fails

Reported by: kbae Owned by: john
Priority: high Milestone: 1.next
Component: selector Version: 1.4.4
Keywords: regression Cc:
Blocked by: Blocking:
Description

Using ~ or > selector in combination with a descendant fails in 1.3.2, but works in 1.2.x.

Example: $(' ~ tr.clsName .subClsName', obj)

See attached sample.

Attachments (1)
  • test.html (0.7 KB) - added by kbae March 13, 2009 04:40AM UTC.
Change History (7)

Changed November 04, 2009 03:26PM UTC by davidserduke comment:1

Seems to work in the most recent versions of the browser that have the querySelectorAll() functionality. But in versions without that I think it is a Sizzle problem. So this problem shows in FF3.5 only if you hide the querySelectorAll().

<!DOCTYPE html>
<html>
  <head>
    <title>Tester</title>
    <script type="text/javascript" src="../jquery.js"></script>
    <script type="text/javascript">
      $(function () {
        document.querySelectorAll = undefined;
        var $result = $("body > div span");
        alert($result.length ? "found" : "not found");
      });
    </script>
  </head>
  <body>
    <div id="outside_div">
      <div id="inside_div">
        <span>Howdy</span>
      </div>
    </div>
  </body>
</html>

Near as I can tell (at least in this case) Sizzle works backwards on the query. So with this query:

$("body > div span");

it finds the span first. Then it looks for the nearest div parent which in this case is inside_div. Next it looks to see if body is the direct parent of inside_div which it is not and fails to make a successful connection on that basis.

I suspect to fix this Sizzle would have to keep an array of matching parents found instead of just the closest parent. Then loop over those for the various cases because sometimes you want the closest but others you might not.

All in all doesn't seem like an easy fix.

Changed October 27, 2010 01:16AM UTC by rwaldron comment:2

milestone: 1.41.4.4
priority: minorhigh
status: newopen
version: 1.3.21.4.3

Confirmed;

"Not Found" when using 1.4.4rc1:

http://jsfiddle.net/rwaldron/SKhr8/3/

"Found" with 1.2.6

http://jsfiddle.net/rwaldron/SKhr8/4/

"Note Found" with 1.3.2

http://jsfiddle.net/rwaldron/SKhr8/5/

Incidentally, I would suspect that qSA does not like mixed descendant selectors

Changed October 27, 2010 09:57PM UTC by snover comment:3

keywords: → regression
milestone: 1.4.41.4.5

Changed January 18, 2011 10:10PM UTC by jitter comment:4

milestone: 1.4.51.next
version: 1.4.31.4.4

Changed January 18, 2011 10:18PM UTC by jitter comment:5

#8003 is a duplicate of this ticket.

Changed June 01, 2011 06:58PM UTC by anonymous comment:6

is this bug fixed yet?

Changed July 11, 2011 06:43PM UTC by john comment:7

_comment0: This does not seem like something that we're going to fix - the result would be prohibitively expensive (both in terms of computation and in terms of file size). Perhaps if we end up rewriting Sizzle at some point we can tackle this issue then.1310409839886172
resolution: → wontfix
status: openclosed

This does not seem like something that we're going to fix - the result would be prohibitively expensive (both in terms of computation and in terms of file size). Perhaps if we end up rewriting Sizzle at some point we can tackle this issue then.

For this specific case you can do: $("body > div").find("span") to achieve a working result.