How to get full anchor href?

anchor, href, javascript, jquery

Solution

`element.href` will get the entire href

FIDDLE

EDIT:

I'll quote something from jQuery's website here:

The .prop() method should be used for boolean attributes/properties and for properties which do not exist in html (such as window.location). All other attributes (ones you can see in the html) can and should continue to be manipulated with the .attr() method.

Since `.attr()` gets the actual value typed in the attribute, as it probably used the native `getAttribute()`, the proper way to do this would be to get the native javascript element, and then use the native `element.href` which will get the href including the domain and pathname etc.

Problem

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.

Original source

Related problems