If you have a regular link in HTML, you can get the value of its href attribute using jQuery’s attr function:
<a id="testLink" href="test/link.html">Test Link</a>`
>>> $('#testLink').attr('href');
testLink.html
Example:
However, if the link was created using jQuery, then in IE 7, this function returns the absolute URL that the browser would access if you clicked on the link (e.g. https://stackoverflow.com/questions/ask/testLink.html), instead of the literal value of the href attribute.
Example:
I’ve also tried this, this.href, and this.getAttribute('href'), and they all return an absolute URL.
Is there any way to get the literal value of the href attribute of a link created by jQuery in IE 7?
If you are creating the link in a way that jQuery is forced to use
.innerHTML, it will work not properly and is documented in: http://api.jquery.com/html/ (also http://api.jquery.com/jQuery/#creating-new-elements) :To fix it, create the link in a way that doesn’t force jQuery to use
.innerHTML:http://jsfiddle.net/xtrEB/12/