Is querySelector supported by all browsers?

2019-03-25 04:38发布

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?

5条回答
小情绪 Triste *
2楼-- · 2019-03-25 04:54

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]).

查看更多
Explosion°爆炸
3楼-- · 2019-03-25 04:57

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           |
查看更多
混吃等死
4楼-- · 2019-03-25 04:59

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).

查看更多
Ridiculous、
5楼-- · 2019-03-25 05:04

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

查看更多
SAY GOODBYE
6楼-- · 2019-03-25 05:12

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

supporting article

查看更多
登录 后发表回答