jquery - Wrong extraction of .attr("href") in IE7 vs all other browsers? -


Is it really true that attr ("href") commands for a link Is handled differently in IE7 compared to all other browsers?

Say I have a page and I have this HTML:

  & lt; A href = "# some anchor" class = "lnkTest" & gt; Link text & lt; / A & gt;  

And this is jQuery:

  var strHref = $ (".lnkTest"). Attr ("href");  

Then the value of the strHref variable in IE7 will be "http://example.com/page.htm#someAnchor" but the other In browsers it will be "# some anchor" .

I believe the last mentioned case is most correct, is it just a case of IE7 bad boy or is it a bug in jQuery?

This is definitely a bug in JQuery, but instead browsers Inconsistent implementation of ' .getAttribute (' href ') - I suggest consistency to use only .get (0) .hrf .

It seems that you can get .get (0) by using attribute text and Mozilla in IE. GetAttribute ('href', 2) If you do not want full URI Note though this will not work in Opera and I have not even tested in Safari / Chrome / others.

You can also remove the domain or the split for the '#' on '#'. Use the second part of the array (0) .href and accept, it also includes '#' (check .length ).


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -