Possible Duplicate:
How to get “raw” href contents in JavaScript
Sometimes you write in your code relative paths to your files, so in the code the href attribute value could be somefile.php yet when clicking of course the anchor would send you to http://www.yourdomain.com/somefiles.php
Now my question is could I somehow obtain the full href of an anchor?
When using $(anchor).attr("href") you only get the relative path.
element.hrefwill get the entire hrefFIDDLE
EDIT:
I’ll quote something from jQuery’s website here:
Since
.attr()gets the actual value typed in the attribute, as it probably used the nativegetAttribute(), the proper way to do this would be to get the native javascript element, and then use the nativeelement.hrefwhich will get the href including the domain and pathname etc.