views:

37

answers:

2

Hi, whats the simplest way to return the "pathname" from an anchor tags href attribute?

example... say I have:

<a href="http://www.example.com/this/is/my/path.html"&gt;Blah&lt;/a&gt;

I need to return only this "/this/is/my/path.html" part.

Ideas? I'm using jQuery if it helps..

Thanks!

+4  A: 

I think you can use pathname

$('a')[0].pathname;
fehays
Yes, it is as simple as that. http://www.devguru.com/technologies/ecmascript/quickref/location_pathname.html
Samuel Sjöberg
+2  A: 

see working example here.. http://jsfiddle.net/TvNmL/

HTML..

<a id='lnk' href="http://www.example.com/this/is/my/path.html"&gt;Blah&lt;/a&gt;

javascript...

alert( document.getElementById('lnk').pathname);
Aaron Saunders