Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is querySelector supported by all browsers?

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?

like image 349
KoolKabin Avatar asked Oct 04 '10 14:10

KoolKabin


People also ask

Does querySelector work in IE?

querySelectorAll works fine in IE9. It even works in IE8.

What can I use instead of document querySelector?

The other alternative is element. query / queryAll . These are alternative methods to querySelector and querySelectorAll that exist on DOM parent nodes. They also take selectors, except these selectors are interpreted relative to the element being queried from.

Is querySelector better than getElementById?

getElementById is better supported than querySelector . querySelector is better supported than getElementsByClassName but querySelector gives you a static node list while getElementsByClassName gives you a live node list. You need to pick the appropriate tool for any given task.

Is querySelector JavaScript or jQuery?

querySelector() and querySelectorAll() are two jQuery functions which helps the HTML elements to be passed as a parameter by using CSS selectors ('id', 'class') can be selected.


4 Answers

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

like image 148
annakata Avatar answered Oct 20 '22 04:10

annakata


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

supporting article

like image 27
Sachin Shanbhag Avatar answered Oct 20 '22 05:10

Sachin Shanbhag


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

like image 44
Milinda Bandara Avatar answered Oct 20 '22 03:10

Milinda Bandara


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           |
like image 24
Weijing Jay Lin Avatar answered Oct 20 '22 04:10

Weijing Jay Lin