Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get pathname from href in Javascript

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">Blah</a>

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

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

Thanks!

like image 294
mike Avatar asked Sep 27 '10 20:09

mike


1 Answers

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

HTML..

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

javascript...

alert( document.getElementById('lnk').pathname);
like image 115
Aaron Saunders Avatar answered Oct 19 '22 03:10

Aaron Saunders