 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Location href Property
The HTML DOM Location href property returns/sets the string corresponding to the URL path.
Syntax
Following is the syntax −
- Returning value of the href property
location.href
- Value of the href property set
location.href = href
Example
Let us see an example for Location href property −
<!DOCTYPE html> <html> <head> <title>Location href</title> <style>    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } </style> </head> <body> <form> <fieldset> <legend>Location-href</legend> <label for="urlSelect">Current URL:</label> <input type="url" size="30" id="urlSelect" value="https://www.example.com/aboutUs"> <input type="button" onclick="gethref()" value="Get href"> <div id="divDisplay"></div> </fieldset> </form> <script>    var divDisplay = document.getElementById("divDisplay");    var urlSelect = document.getElementById("urlSelect");    function gethref(){       divDisplay.textContent = 'URL Path: '+location.href;    } </script> </body> </html> Output
This will produce the following output −
Before clicking ‘Get href’ button −

After clicking ‘Get href’ button −

Advertisements
 