Reputation: 11697
The following code will return as undefined
:
$('a').each(function () {
console.log($(this).pathname);
});
My anchors look like this:
<a href="../foo/">Foo</a>
What am I doing wrong? If it is not possible then how can I return the full url?
Upvotes: 1
Views: 1303
Reputation: 70199
In HTML5 browsers you can use this.pathname
:
$('a').each(function () {
console.log(this.pathname);
});
pathname
is a property of the Anchor element, not of a jQuery object.
Edit: The anchor's pathname
property has been standardized in HTML5, but even IE6 supports it natively.
Upvotes: 3
Reputation: 41523
Use
$(this).attr('href')
The .attr()
method extracts an attribute. You can see the docs at http://api.jquery.com/attr/
Upvotes: 0