D
David Mark
For the typical neophyte, CSS selectors are magic. Put in a selector,
get out a collection of matching elements. What could be easier?
Turns out, almost anything would be easier.
For the typical library author, attribute handling is also magic, so
they never got close to creating a reliable query solution. They all
fail in similar ways, varying slightly with the specific
misconceptions of their respective author(s). Not unexpectedly, years
of slap-dash debugging by hapless users and contributors has failed to
fix the problems (none has a clue what is going on under the hood).
If they can't fix attr, they sure as hell can't fix the queries.
Now they want to deprecate (on paper) every browser that fails to meet
their warped expectations. It's ironic that such a move makes them
virtually superfluous (take away "Sizzle" and all that is left of
jQuery is an ill-advised, "overloaded" clunker of an OO DOM
interface).
These issues come up over and over in the various mailing lists for
the "major" libraries. They are usually answered with guesswork (e.g.
try this instead) or ignored.
http://groups.google.com/group/jquery-dev/browse_thread/thread/31f1592d11c3bbe6
http://groups.google.com/group/jquery-en/browse_thread/thread/23d0f3c908410e3f#
This bit says it all:-
$(':checkbox[name=number]').click(function() {
if ($(this).is(':checked')) alert($(this).val());
});
This is the sort of thing that is sold as "simpler" than basic DOM
scripting. Sure looks like the function body - for example - could be
reduced to something like:-
if (this.checked) alert(this.value);
Smaller, more readable, no function calls, no guesswork about what
goes on in those functions and it's impervious to jQuery "upgrades".
It's even less typing (as if that was ever a rational concern).
A demonstration:-
http://www.cinsoft.net/queries.html
The example uses jQuery, but the rest will fail in similar fashion.
And these issues are just the tip of the iceberg for most of them.
They could even be considered "edge cases" (a recurring theme for
these things), except that there are tons of other mistakes in-
between. These are simply the easiest to demonstrate.
The worst implementation has got to be YUI as its hasAttribute wrapper
treats empty attribute values the same as missing attributes. (!)
<input type="checkbox" checked>
elCheckbox.getAttribute('checked') // '' in most browsers
<input type="checkbox">
elCheckbox.getAttribute('checked') // null in most browsers
YUI3, the latest and "greatest" time-saver from Yahoo will report an
empty string for both. How is that helping? All it does is reinforce
the myth that cross-browser scripting is impossible. I guess for
Yahoo (and the rest of these bums), it _is_ impossible.
No, the query engine in My Library is not perfect either (though it is
much closer than the rest of these things), but then I never advocated
using CSS selectors to query the DOM in the first place. I spent a
weekend putting the thing together just to see what was involved. My
advice is to avoid it (there are plenty of simpler alternatives for
finding elements).
Furthermore, I didn't bother trying to support _all_ of the selector
types as that's just silly. The "majors" love to tick off the
selectors they "support", but it doesn't really count if they don't
work _reliably_ cross-browser (like gEBI and gEBTN). For those
wondering, if a selector type is on the speed test page, it's
supported.
For aspiring library luminaries, start with a foundation like this:-
http://www.cinsoft.net/attributes.html
....and you can write a serviceable query engine (and have some hope of
success in "old" browsers like IE7 and Opera 9). I will transplant
these functions back into My Library when I have a chance (or if there
is a specific request.).
But I still say it is a waste of time (three years and counting for
the "majors" and a couple of weekends for me).
get out a collection of matching elements. What could be easier?
Turns out, almost anything would be easier.
For the typical library author, attribute handling is also magic, so
they never got close to creating a reliable query solution. They all
fail in similar ways, varying slightly with the specific
misconceptions of their respective author(s). Not unexpectedly, years
of slap-dash debugging by hapless users and contributors has failed to
fix the problems (none has a clue what is going on under the hood).
If they can't fix attr, they sure as hell can't fix the queries.
Now they want to deprecate (on paper) every browser that fails to meet
their warped expectations. It's ironic that such a move makes them
virtually superfluous (take away "Sizzle" and all that is left of
jQuery is an ill-advised, "overloaded" clunker of an OO DOM
interface).
These issues come up over and over in the various mailing lists for
the "major" libraries. They are usually answered with guesswork (e.g.
try this instead) or ignored.
http://groups.google.com/group/jquery-dev/browse_thread/thread/31f1592d11c3bbe6
http://groups.google.com/group/jquery-en/browse_thread/thread/23d0f3c908410e3f#
This bit says it all:-
$(':checkbox[name=number]').click(function() {
if ($(this).is(':checked')) alert($(this).val());
});
This is the sort of thing that is sold as "simpler" than basic DOM
scripting. Sure looks like the function body - for example - could be
reduced to something like:-
if (this.checked) alert(this.value);
Smaller, more readable, no function calls, no guesswork about what
goes on in those functions and it's impervious to jQuery "upgrades".
It's even less typing (as if that was ever a rational concern).
A demonstration:-
http://www.cinsoft.net/queries.html
The example uses jQuery, but the rest will fail in similar fashion.
And these issues are just the tip of the iceberg for most of them.
They could even be considered "edge cases" (a recurring theme for
these things), except that there are tons of other mistakes in-
between. These are simply the easiest to demonstrate.
The worst implementation has got to be YUI as its hasAttribute wrapper
treats empty attribute values the same as missing attributes. (!)
<input type="checkbox" checked>
elCheckbox.getAttribute('checked') // '' in most browsers
<input type="checkbox">
elCheckbox.getAttribute('checked') // null in most browsers
YUI3, the latest and "greatest" time-saver from Yahoo will report an
empty string for both. How is that helping? All it does is reinforce
the myth that cross-browser scripting is impossible. I guess for
Yahoo (and the rest of these bums), it _is_ impossible.
No, the query engine in My Library is not perfect either (though it is
much closer than the rest of these things), but then I never advocated
using CSS selectors to query the DOM in the first place. I spent a
weekend putting the thing together just to see what was involved. My
advice is to avoid it (there are plenty of simpler alternatives for
finding elements).
Furthermore, I didn't bother trying to support _all_ of the selector
types as that's just silly. The "majors" love to tick off the
selectors they "support", but it doesn't really count if they don't
work _reliably_ cross-browser (like gEBI and gEBTN). For those
wondering, if a selector type is on the speed test page, it's
supported.
For aspiring library luminaries, start with a foundation like this:-
http://www.cinsoft.net/attributes.html
....and you can write a serviceable query engine (and have some hope of
success in "old" browsers like IE7 and Opera 9). I will transplant
these functions back into My Library when I have a chance (or if there
is a specific request.).
But I still say it is a waste of time (three years and counting for
the "majors" and a couple of weekends for me).