Get pathname from href in anchor element in Javascript - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Get pathname from href in anchor element in Javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//w w  w. java2 s . c  om
        console.log( document.getElementById('lnk').pathname);
    });

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

Related Tutorials