Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE8 does not support querySelectorAll

I tried to use document.querySelectorAll(), but IE8 throw error, that

Object doesn't support this property or method

var titleCheckBox = document.querySelectorAll(""); 

Here http://www.quirksmode.org/dom/w3c_core.html#t13 written, that IE8 support this method. What I doing wrong?

like image 989
Roman Makhlin Avatar asked Jun 04 '13 14:06

Roman Makhlin


People also ask

Can you use forEach on querySelectorAll?

Since nodeList selected by querySelectorAll has an array-like structure so you can directly apply forEach method with it and pass element as the first element in the callback function.

Is getElementsByClassName faster than querySelectorAll?

Specifically, getElementById() and getElementsByClassName() are more than twice as fast as querySelector() and querySelectorAll() .

How do I access querySelectorAll?

The querySelectorAll() method in HTML is used to return a collection of an element's child elements that match a specified CSS selector(s), as a static NodeList object. The NodeList object represents a collection of nodes. The nodes can be accessed by index numbers. The index starts at 0.

What is the difference between getElementsByClassName and querySelectorAll?

querySelectorAll successfully removes the classes from all the elements, but getElementsByClassName only removes the classes from about half the elements.


2 Answers

Check that your page isn't in Quirks mode or Compatibility mode. You can use the F12 dev tools to confirm this. Press F12 and look in the top-right corner of the resulting window. If you see "Compatibility" or "Quirks" in the mode description, then you've found the problem.

  • Quirks mode: this is usually triggered by a missing or broken Doctype. If this is the case, make sure your page starts with the following:

    <!DOCTYPE html> 
  • Compatibility mode (IE7 mode): This may be triggered if you're viewing the page locally (ie running it on your local machine, eg for testing, or on your local network). In this case, you are being hit by an IE config setting that you should disable. Go to the Tools menu, and pick the Comaptibility View Settings option. Untick the compatibility options, and the page should start working.

    Compat mode may also be triggered (or avoided) by an X-UA-Compatibility meta tag. If you're having trouble with compatibility mode, this is a good way to avoid it: Add the following line to your code:

    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 

Either (or both) of the above could be the problem, but my guess is that the problem is compatibility mode. The compat-mode-on-intranet-sites setting is suprisingly little known, and catches a lot of people out, even some seasoned developers.

like image 161
Spudley Avatar answered Oct 10 '22 05:10

Spudley


IE8 only supports querySelectorAll() in standards mode. From MSDN:

The Selectors API is defined as part of the Selectors API specification and is only available to Web pages displayed in IE8 standards mode.

Chances are your page doesn't have a proper DOCTYPE declaration; you will need to add one.

like image 35
BoltClock Avatar answered Oct 10 '22 05:10

BoltClock