Announcing the jQuery Foundation
blog.jquery.com
blog.jquery.com
JQuery just gets in the way these days.
$("#element") is an anti-pattern. That code should just return the DOM node, not some silly object with unknown attributes. We're way past the point where you need to abstract the entire document object model, and I argue you should never have done that to begin with.
$('#element').click(function(){
this.id; <- the DOM element
$(this).attr('id'); <- rewrap required
}
Also, same result: var x = $('#element');
x.attr('id'); <- jQuery object
x[0].id; <- DOM element
Your argument that it's "a silly object with unknown attributes" just means you don't know very much jQuery. And if you're ever curious what attributes it has you can let Developer Tools or Firebug tell you with the auto-suggest dropdown: var x = $('#element');
x. it lets you chain jQuery functions,
That's also an anti-pattern. JQuery was designed to hide iteration from designers who can't code. I'm floored that people that actually know how to program still think it's a good idea.$('DIV').click(..).color()...border()...
It might look fancy, but all it's doing is obscuring the fact that iteration might be occurring on each command which for obvious reasons would be a bad idea. A designer might not care, but a programmer who knows JavaScript will probably write something like this instead:
var divs = document.getElementsByTagName('DIV');
divs.forEach(function(div) {
div.onClick = ..
div.style....
});
JQuery provides a nice polyfill for older browsers, but the way the API works just gets in the way for people who know JavaScript and DOM.