HTML DOM Anchor pathname attribute is used to set or return the pathname of the href attribute.
The following is the syntax for setting the pathname attribute -
anchorObj.pathname = path
Above, path is the path name of the URL.
The following is the syntax for returning the pathname attribute-
anchorObj.pathname
Now let us see an example of implementing the DOM anchor pathname attribute-
Real-time demonstration
<!DOCTYPE html> <html> <body> <h1>Company</h1> <p><a id="mylink" hreflang="en" href="https −//abc.com/abc.html/#new">Products</a></p> <h2 id="myid"></h2> <button onclick="display1()">Display pathname</button> <button onclick="display2()">Display hreflang</button> <script> function display1() { var a = document.getElementById("mylink").pathname; document.getElementById("myid").innerHTML = a; } function display2() { var a = document.getElementById("mylink").hreflang; document.getElementById("myid").innerHTML = a; } </script> </body> </html>
Above, click "Show path name" to display the path part-
The above is the detailed content of HTML DOM Anchor pathname attribute HTML DOM Anchor pathname property returns the pathname portion of the URL. For more information, please follow other related articles on the PHP Chinese website!