D
David Mark
Out of curiosity about Microsoft's newfound understanding of
attributes, I put together a set of tests. Two sets, actually:-
http://www.cinsoft.net/attributes.html
One calls get/removeAttribute methods assuming they work consistently
across all browsers (a common strategy). Results are almost exactly
as expected. All green in modern standards-based browsers tested
(e.g. Chrome, FF3.5.) Mostly green in IE8 standards mode (yes,
they've _still_ got some mistakes in there). Put IE8 in
"compatibility view" and all hell breaks loose (all but three tests
fail).
Out of further curiosity, I added a second set of the same tests using
wrapper functions and a feature test proposed here two years ago. All
is exactly the same, except that now IE8 compatibility mode passes all
but one test (enctype). I believe IE6/7 will pass all of them as
there is a workaround in there for that attribute.
The moral is to avoid these methods whenever possible (virtually
always). Calling them outside of a suitable wrapper is surefire
disaster as users can affect the behavior of these methods with a
toolbar button in IE8 (and what a silly button that is).
When might these methods be handy? CSS selector queries (if you find
them useful), parsing/serializing markup and XML elements (e.g SVG)
come to mind. Not a lot else.
But in the "real world", virtually every jQuery example uses its attr
method, which calls get/setAttribute, etc. The big problem is that
the people reading (and writing) these examples are taking it on blind
faith that the jQuery authors understand these issues (they clearly do
not). Maybe a nice picture will finally drive the point home.
attributes, I put together a set of tests. Two sets, actually:-
http://www.cinsoft.net/attributes.html
One calls get/removeAttribute methods assuming they work consistently
across all browsers (a common strategy). Results are almost exactly
as expected. All green in modern standards-based browsers tested
(e.g. Chrome, FF3.5.) Mostly green in IE8 standards mode (yes,
they've _still_ got some mistakes in there). Put IE8 in
"compatibility view" and all hell breaks loose (all but three tests
fail).
Out of further curiosity, I added a second set of the same tests using
wrapper functions and a feature test proposed here two years ago. All
is exactly the same, except that now IE8 compatibility mode passes all
but one test (enctype). I believe IE6/7 will pass all of them as
there is a workaround in there for that attribute.
The moral is to avoid these methods whenever possible (virtually
always). Calling them outside of a suitable wrapper is surefire
disaster as users can affect the behavior of these methods with a
toolbar button in IE8 (and what a silly button that is).
When might these methods be handy? CSS selector queries (if you find
them useful), parsing/serializing markup and XML elements (e.g SVG)
come to mind. Not a lot else.
But in the "real world", virtually every jQuery example uses its attr
method, which calls get/setAttribute, etc. The big problem is that
the people reading (and writing) these examples are taking it on blind
faith that the jQuery authors understand these issues (they clearly do
not). Maybe a nice picture will finally drive the point home.