3

Who can tell me does sizzle support namespace in selector? If it supports, who can give me some examples, I can't find such information in API docs.

Thanks!

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
user2155362
  • 1,657
  • 5
  • 18
  • 30

1 Answers1

1

No, Sizzle does not support the namespace selector.

The CSS selector for namespaces is namespace|. This selector matches a span in any namespace (including the default namespace): *|span.

This selector works with jQuery in modern browsers: jsfiddle.net/U7my4

Modern browsers support document.querySelectorAll() natively, so jQuery uses that by default. Sizzle is the fallback selector engine that is used for older browsers. Basically, we're talking about IE7 and IE6, and these are hardly used any more outside of China. By loading that jsFiddle's frame page in IE7-mode, you can force jQuery to use sizzle. And it fails with an error message:

Syntax error, unrecognized expression: *|span

gilly3
  • 87,962
  • 25
  • 144
  • 176
  • Yes, I couldn't get an example using any other namespace to work either. Even when following the syntax for the [CSS3 namespaces module](http://www.w3.org/TR/css3-namespace/). *But,* the point is that the selector itself *is* supported by modern browsers. Though it may not be of any practical use. – gilly3 Jul 13 '13 at 02:09
  • 1
    That's because `@namespace` is not a selector. It's a CSS at-rule. Since you can't actually write CSS in `querySelectorAll()`, it's quite simply not fully supported. Namespaces in `querySelectorAll()` are covered here: http://www.w3.org/TR/selectors-api/#resolving-namespaces – BoltClock Jul 13 '13 at 02:10
  • @BoltClock - That's interesting. I would've thought that the namespace declared with an at-rule would be global and valid in the call to `querySelector()`. But, I can't even get an `@namespace` to work with plain CSS: [jsfiddle.net/U7my4/2](http://jsfiddle.net/U7my4/2/) – gilly3 Jul 13 '13 at 04:44
  • I have never been able to get `@namespace` to work with jsFiddle. My impression is that it just doesn't support XHTML, even if you choose the XHTML doctype. Interestingly, browsers declare a default namespace that does work with the `*|` prefix. See http://stackoverflow.com/questions/13651841/are-css3-namespaces-used-for-anything-except-xml/13672828#13672828 for details. – BoltClock Jul 13 '13 at 04:45