Wrong extraction of .attr(“href”) in IE7 vs all other browsers?

It’s certainly not a bug in jQuery but instead browsers’ inconsistent implementations of .getAttribute('href') – I suggest using just .get(0).href for consistency.

Seems like you can access the attribute text in IE and Mozilla using .get(0).getAttribute('href', 2) if you don’t want the absolute URI. Note however this won’t work in Opera and I haven’t tested in Safari/Chrome/anything else.

You could also strip out the domain or split on ‘#’ for .get(0).href and use the second part of the array assuming it even contains ‘#’ ( check .length ).

http://www.glennjones.net/Post/809/getAttributehrefbug.htm

Leave a Comment