Home > Web Front-end > HTML Tutorial > HTML DOM Anchor pathname attribute HTML DOM Anchor pathname property returns the pathname portion of the URL

HTML DOM Anchor pathname attribute HTML DOM Anchor pathname property returns the pathname portion of the URL

王林
Release: 2023-09-07 21:37:01
forward
1503 people have browsed it

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
Copy after login

Above, path is the path name of the URL.

The following is the syntax for returning the pathname attribute-

anchorObj.pathname
Copy after login

Now let us see an example of implementing the DOM anchor pathname attribute-

Example

Real-time demonstration

<!DOCTYPE html>
<html>
<body>
<h1>Company</h1>
<p><a id="mylink" hreflang="en" href="https &minus;//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>
Copy after login

Output

HTML DOM Anchor pathname属性

HTML DOM Anchor pathname属性返回URL中的路径名部分

Above, click "Show path name" to display the path part-

HTML DOM Anchor pathname attribute

HTML DOM Anchor pathname property returns the pathname portion of the URL

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template