views:

148

answers:

4

Hello

I was checking out HTML5 new javascript commands and there is something similar to:

var els = document.querySelectorAll("ul li:nth-child(odd)");

This allows you to find all elements by css syntax. But I sure Jquery also has something a little similar to this.

The question is, as browsers are getting better javascript APIs...

  • JQuery will not exist in future? Is it safe to keep JQuery in our websites for the next years?
+13  A: 

jQuery does a lot more than just the selector engine (Sizzle), and Sizzle uses querySelectorAll() if it's available since the version included with jQuery 1.4.3.

No, it's not going anywhere, the selectors are only one piece of the puzzle.

Nick Craver
+3  A: 

Of course it's safe to keep JQuery on our websites. Remember, you link to the library, and that's based off of Javascript. It doesn't require any special software on the client side (apart from Javascript).

As for JQuery being obsolete in the future, no no no no no. It does so much more than just selectors.

Christian Mann
A: 

As others have mentioned, jQuery is more then a selector engine, it provides event handling, chaining, animations, UI toolkits, abstraction and a lot more. Take a look at the jQuery website.

Selectors by themselves aren't that useful. You use selectors to execute actions on those elements.

jQuery provides:

  • JavaScript abstraction
  • Animation
  • UI controls and widgets (Sliders, accordions, etc)
Rogue Coder
To be clear, jQuery UI is not in jQuery core, it's a separate project entirely.
Nick Craver
Yes, I'm aware. It does utilise jQuery core however
Rogue Coder
+4  A: 

It's true that jQuery is a lot more than just a selector engine. But it does seem like a lot of what else it does might become obviated by bleeding edge browsers, for example:

Animations

jQuery's Effects such as animate(), fadeOut(), etc are taken care of by CSS transitions.

Ajax

jQuery takes care of abstracting browser differences, such as using ActiveXObject("Microsoft.XMLHTTP") instead of XmlHttpRequest() in older versions of IE. This fallback is quickly becoming unnecessary.

jQuery's Ajax also provides JSON-P for cross-domain Ajax. This won't be necessary with proper cross domain XmlHttpRequest as implemented in the latest browsers.

Event binding

jQuery abstracts away IE's attachEvent vs everyone else's addEventListener. But since IE9 will provide the standard method, that abstraction will also become unnecessary.

This all means that "dropping down to raw JavaScript" will become less barbaric than in the past. However, it's still nice to have the library. Take jQuery's central genius, the idea of sets acted upon in parallel. In jQuery you write:

jQuery("#something").hide();

In raw JavaScript you write:

var things = document.querySelectorAll("#something");
if (things.length > 0) {
    things[0].style.display = "none";
}

This kind of grace will never be fully available from builtin DOM methods.

darkporter
whats even better then binding is the event delegation stuff with .live
Matt Briggs
Yeah good point. I can't think of anything in the HTML5 plans that provides live() functionality.
darkporter