It means:
1. It is broken.
2. The people charged with fixing it are incapable.
3. It complicates, rather than simplifies
To quote John Resig: "broke is broke."
LOL. It's been booked, printed and sentenced to life (three strikes
and all.)
You are just inconceivably thick. Do you normally need to "be
careful" when setting DOM properties?
http://jquery.open2space.com/node/13
http://mindforks.blogspot.com/2008/11/using-attr-for-aria-in-jquery-u...
http://www.nabble.com/attr("href")-giving-full-path-instead-of-re...
Oops, didn't realize that was actually a GG.
http://groups.google.com/group/jquery-en/browse_thread/thread/ea68e18af9f66296#
This post is from a week ago, so it overlaps our recent discussion
about this issue, which is basically a re-hash of an argument from the
fall of 2007.
It starts out:
"I'm wanting to read in the exact string that's contained in an
anchor's href attribute in order to use it as the POST variable list
for an Ajax call to a PHP script, however in IE6 and 7 the string read
from the href attribute ends up being the absolute path, not just the
href attribute. Here's exactly what's happening:
vars = $("a").attr("href");
alert(vars);
<a href="page=2">This should return "page=2"</a>
What I get when running locally in all browsers but IE is what is
expected, an alert box with page=2 in it. In IE, I get "http://
localhost/page=2". Is there some way to get it to behave either one
way or the other in all browser instances? I really don't want to have
to detect for IE, then extract what I want from the string if it is."
Sure, in this example:
vars = document.getElementsByTagName('a')[0].href
But this wasn't posted here. Instead he got this:
"
http://www.glennjones.net/Post/809/getAttributehrefbug.htm describes
the issue and gives a solution."
Not exactly, but the solution proposed was better than this:
"$("a")[0].href will probably work consistently."
How elegant, we are to bypass the jQuery "convenience" method as it
doesn't do anything predictable (at least to the uninitiated.) The
docs didn't say anything about that.
After a bit of confusion, the OP added:
"The way I currently have it will not work with javascript turned off
either. I'm doing it this way only because the client is requiring the
user to have Javascript enabled to use the site (it's a backend system
for very specific clients). They want to add all sorts of animations
and effects like everyone wants to do once they see JQuery animations
in action."
jQuery expert @2 replied:
"IE has a second "flag" argument for getAttribute that, when set to 2,
is supposed to get the literal value of the attribute rather than
their special-sauce value.
So, this.getAttribute('href', 2) *should* get the relative href.
(note: no need to do $(this)[0] ; this works just fine)
jQuery uses that flag internally, so .attr('href') should do the same
thing:
var attr = !jQuery.support.hrefNormalized && notxml && special
// Some attributes require a special call on IE
? elem.getAttribute( name, 2 )
: elem.getAttribute( name );
I believe that this works in every case except when the href is set
via JavaScript. In that case, I'm not sure anything can be done."
Except when it doesn't work. Certainly he meant in every case that he
knows about, except when jQuery is used to set the attribute as it
uses the attr method, so there is no telling what to expect from the
DOM after that. GIGO.
And why is a code dissection needed here anyway? Couldn't they have
pointed the OP to the documentation? Perhaps they knew it was as
confused as they are.
OP:
"... I'm pretty sure I'm reading you right, but are you saying that by
all accounts JQuery should account for this and return the string-
literal value of href and not IE's absolute path? If so, it's not
working properly ... That means that if JQuery is supposed to sort
this out for me, it's not. If you meant that I'd absolutely have to
use Javascript's getAttribute(), then I'll try that and see if it
works."
Sure, try "Javascript's getAttribute" that and see if it works. This
is programming by collaborative misunderstanding.
OP:
"After replacing $(this).attr("href") with this.getAttribute("href",
2) I get the same result. If I output the attribute, IE still shows
the absolute path."
All of this flailing to get a consistent result with:
this.href;
Not there yet, but it does have a (more or less) happy ending.
jQuery support:
"Yes, I believe you're reading me right. Strange, though. I'm not able
to reproduce the problem you're having. Take a look here:"
Not strange at all. Neither has mentioned which version of jQuery
they are using and only one has indicated an IE version.
After some more suggestions about parsing URI's (!), the OP finally
figures it out for himself:
"Right, it's not hard, it was just unexpected is all. I guess I've
gotten used to JQuery working the same in "all browsers."
I've got it working now with some old-fashioned Javascript."
Get used to jQuery not working the same in all browsers.
So he has noted a landmine on *his* map. The others seem oblivious
and completely ignorant of the fact that the attr method makes getting
and setting properties *much* more complicated than it needs to be and
leads to code that changes behavior from one version to the next and
is virtually impossible to debug. Wasn't jQuery supposed to save you
from "good old-fashioned Javascript?"
Then this is this ominous coda:
"I experienced the same problem while developing a plugin that does
some tricks with the page content during the ready event. I noticed
that attr('href') works fine if I don't manipulate the body tag
content. IE won't return the correct href attribute if I do so.
The code I used to workaround the problem looks like this:
$('a').attr('xref', function() {
return $(this).attr('href');
});
....
document.body.innerHTML = someContent + document.body.innerHTML;
....
$('a').attr('href', function() {
return $(this).attr('xref');
}).removeAttr('xref');
Hope this helps."
Not by a long shot. Notice the "if I manipulate" (with jQuery)
comment. Again, GIGO. And advising people to add expandos to bridge
the gap in jQuery's attribute logic is obviously ludicrous. Now how
many people will run out and do just that?
Nobody has posted to the thread since, so I assume the issue is
considered closed. Doesn't really matter as they obviously can't
rewrite the attr method (for fear of breaking workarounds based on bad
assumptions.)
So is this really the "next best thing" to DOM properties? And is
this really a viable support group?