IE8 is Gonna Rock

So maybe my title was a bit overdramatic. But in the announcement of IE8’s features, one jumped out at me as a potentially game-changing feature.

http://www.microsoft.com/windows/products/winfamily/ie/ie8/readiness/DevelopersNew.htm#dom

Yes.

That’s right.

“Selectors are a query language for searching and “selecting” tags (elements) within a webpage. They are most commonly seen in CSS to “select” a group of elements to which certain properties will be applied:

Selector{
   property: value;
   property2: value;
}

In Internet Explorer 7 there is no way of “executing” the selector independently of CSS. Internet Explorer 8’s implementation of the Selectors API is based on the W3C Working Draft: http://www.w3.org/TR/selectors-api/”

Yes. You read that correctly. To the extent of IE8’s support for CSS2.1 (which should be relatively complete, according to their announcement), it will be possible to use the standards-compliant querySelector and querySelectorAll in IE to get collections of elements at native speed. This means fast class-name lookup, fast attribute lookup, and much much more.

Here’s a lame example of its use from an IE8 whitepaper:

function doValidation ()  {
// Retrieve the required elements by using Selectors
   // Selects all the form fields with 'required' classes
var reqs = document.querySelectorAll(".required");
   // Set the flag to false by default
var missingRequiredField = false;
// Validate that the form data is not empty
for (var i = 0; i < reqs.length; i++)  {
if (reqs[i].value == "")
         missingRequiredField = true;
   }

Yep. It is what it looks like. Finally, the days of slow IE selectors may be coming to an end. And finally, one where MS is ahead of the curve (in fact, a lot of the IE8 improvements are pretty neat and forward-looking; I recommend taking a look at it)

3 Comments so far

  1. Kamal Gill on March 21st, 2008

    Safari 3.1, released 18 March 2008, natively supports querySelector and querySelectorAll (and, btw, getElementsByClassName).

    I suspect Firefox 3 and the next Opera release will also support the querySelector* API.

    Selectors API spec: http://www.w3.org/TR/selectors-api/

  2. whoismario on March 23rd, 2008

    Do you know if Apple plans on allowing a focus event on a div in Safari? I have some behavior I’d like to attach to a div via a selector, but without the focus event most of it is useless in Safari and Opera.

  3. Vitaly Sharovatov on April 11th, 2008

    Yes, IEb1 supports Selectors API, but:
    1) as IE doesn’t have proper namespace support, we can’t use Selectors API to query for elements in a different namespace
    2) as the techspec doesn’t offer any solution for the potential history theft possibility, IE8b1 ignores :link and :visited pseudoclasses to prevent history theft

    I’ve blogged about that here.

    Regarding WebKit support for Selectors API: on my Windows machine latest build of Webkit (r31786) is much slower in querying using Selectors API then IE8b1. I used this test and will post results a little bit later.

    And I didn’t notice any support for Selectors API neither in Firefox 3.04b nor in Opera 9.50 beta.

    Vitaly

Leave a reply