whats the simplest way to return the "pathname" from an anchor tags href attribute?
example... s开发者_运维问答ay 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!
I think you can use pathname
$('a')[0].pathname;
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);
I noticed there's still no proper answer that deals with the IE bug that @Funka mentioned, so here's my solution:
HTML
<a href="/foo" id="foo">My link</a>
JS
document.getElementById("foo").getAttribute("href");
results '/foo' on all browsers
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论