Is querySelector supported by all browsers?
Asked Answered
G

5

18

I would like to know is querySelector supported by all browsers? is not what's alternate for it to use?

I have tested it with IE8, FF3, Chrome 4. Its fine for me. I do not have old browsers. So i would like to know if old browsers will give problem to me or not?

Globulin answered 4/10, 2010 at 14:42 Comment(1)
2017 update: querySelector() is very widely supported. Go ahead and use it!Dixiedixieland
B
17

IE7< don't support it and IIRC IE8 has issues with namespaces. There's at least one more esoteric browser out there with major issues but I don't recall which it is.

Basically there is no unified expression-based DOM method, and absolutely your best bet is to use a library (the ubiquitous "use jquery" answer, but you should at least check out Sizzle if you have a problem with large libraries) because rolling your own is more effort than reasonably worthwhile (I speak from experience).

Brilliant answered 4/10, 2010 at 14:48 Comment(6)
+1 for mentioning Sizzle, the little selector engine used by jQuery and PrototypeSelfinterest
Another selector engine that's worth mentioning: NWMatcher. Sizzle claims "CCS3 Compliance" but has known problems.Kingcup
2016 update: YES, just use document.querySelector()! :)Dixiedixieland
@rinogo: No, SAP browser doesn't support it.Brufsky
@StefanSteiger - I'm not familiar with SAP browser. Do you have figures on the market share of this browser? Nowadays (2017), querySelector() is very widely supported.Dixiedixieland
@rinogo: No - but SAP-Browser is very old. It's part of some SAP systems/extensions. Probably a very old Java embedded browser control.Brufsky
C
9

QuerySelector is supported on Firefox 3.1+, IE8+ (only in IE8 standards mode), and Safari 3.1+ browsers.

supporting article

Cykana answered 4/10, 2010 at 14:45 Comment(0)
B
2

I tested it with FireFox - It is perfectly work. In IE there is a issue when you use the document with quirk mode (without using DOCTYPE HTML)

Try to use in the HTML document

Biramous answered 6/9, 2013 at 9:49 Comment(0)
S
2

You can check MDN for detail information.

| Feature       | Chrome |  Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
| ------------- | ------ | ---------------- | ----------------- | ----- | --------------- |
| Basic support |   1    |  3.5             |   8               | 10    |   3.2           |
Suet answered 13/5, 2016 at 10:25 Comment(0)
G
1

The best alternative is to use a third-party library that abstracts all that nasty browser-specific code away, like YUI or jQuery (I'm not as familiar with Prototype et al, so I can't say for sure if it uses the query* methods [when available]).

Geez answered 4/10, 2010 at 14:47 Comment(1)
PrototypeJS doesn't wrap the DOM with CSS query selection. It is more of an extension to JavaScript as it uses ID names as selectors. Example: <div id="customerOrders"> ~ $('customerOrders').Horbal

© 2022 - 2024 — McMap. All rights reserved.