Get the current URL using jQuery Last Updated : 14 Dec, 2023 Comments Improve Suggest changes Like Article Like Report The current URL in jQuery can be obtained by using the 'href' property of the Location object which contains information about the current URL. The href property returns a string with the full URL of the current page. We can access the value of the href property using two different methods of jQuery. Table of Content Using the attr() methodUsing the prop() methodUsing the attr() methodThe attr() method can be used to get the value of the href attribute of the current window location by simply passing it to the method in the form of a string. Syntax:$(location).attr('href')Example 1: This example illustrates getting the current site detail using the attr() method in jQuery. HTML <!DOCTYPE html> <html> <head> <title>Get current URL using jQuery?</title> </head> <body> <h1 style="color: green">GeeksForGeeks</h1> <b>Get current URL using jQuery?</b> <p> Click on the button below to get the current page URL </p> <p> The current URL is: <span class="output"></span></p> <button id="btn">Get current </button> <script src="https://code.jquery.com/jquery-3.3.1.min.js"> </script> <script> $('#btn').click(function() { currLoc = $(location).attr('href'); document.querySelector('.output').textContent = currLoc; }); </script> </body> </html> Output: Getting the current URL using jQueryUsing the prop() methodThe prop() method can also be used to get the current location URL in the same way as the attr() method was used by passing the href property as parameter to it. Syntax:$(location).prop('href');Example: This example illustrates the use of the prop() method to get the current URL of the window location. HTML <!DOCTYPE html> <html> <head> <title>Get current URL using jQuery?</title> </head> <body> <h1 style="color: green">GeeksForGeeks</h1> <b>Get current URL using jQuery?</b> <p> Click on the button below to get the current page URL </p> <p> The current URL is: <span class="output"></span></p> <button id="btn">Get current </button> <script src="https://code.jquery.com/jquery-3.3.1.min.js"> </script> <script> $('#btn').click(function() { currLoc = $(location).prop('href'); document.querySelector('.output').textContent = currLoc; }); </script> </body> </html> Output: jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous for its philosophy of “Write less, do more". You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples. Comment More infoAdvertise with us Next Article Get the current URL using jQuery sayantanm19 Follow Improve Article Tags : Web Technologies JQuery jQuery-Questions Similar Reads How to Get the Current URL using JavaScript? Here are two different methods to get the current URL in JavaScript.1. Using Document.URL PropertyThe DOM URL property in HTML is used to return a string that contains the complete URL of the current document. The string also includes the HTTP protocol such as ( http://).Syntaxdocument.URLReturn Val 1 min read How to get the current URL using AngularJS ? In this article, we will see how to get the current URL with the help of AngularJS, along with knowing its basic implementation through the examples. This task can be accomplished in 2 ways, i.e., by implementing the $location.absURL() method to get the complete URL of the current page, & the 2n 2 min read How to get current_url using Selenium in Python? While doing work with selenium many URL get opened and redirected in order to keeping track of URL current_url method is used. The current_url method is used to retrieve the URL of the webpage the user is currently accessing. It gives the URL of the current webpage loaded by the driver in selenium. 2 min read Get the Current URL within a Django Template Django, a high-level Python web framework, encourages rapid development and clean, pragmatic design. One common requirement when developing web applications is to access the current URL within a template. This can be useful for various purposes such as highlighting the active link in a navigation me 3 min read jQuery event.currentTarget Property jQuery event.currentTarget property is used to return the current DOM element within the event bubbling phase. The event.currentTarget is typically equal to "this". Syntax:event.currentTargetParameters:event: It is a required parameter and this parameter comes from the event binding function.Exampl 1 min read How to Read the Current full URL with React? In React applications, it is often necessary to read the current full URL for various purposes, such as routing, conditional rendering, or logging. There are two common approaches to achieve this: using the window.location object and using the useLocation hook from react-router-dom. Prerequisites:NP 3 min read How to Get The Current URL Domain in Next.js ? In Next.js, we can get current url domain with the help of built-in methods like window and document location. In this article, we'll explore different approaches and best practices for obtaining the current URL domain in Next.js applications.The approaches to get the URL of the current domain in ne 3 min read How to make an URL Input using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating an URL Input using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=âstylesheetâ href=âh 1 min read jQuery | Misc get() Method The get() Method in jQuery is used to get the DOM element specified by the selectors. Syntax $(selector).get(index) Parameters: This method accepts single parameter index which is optional. It is used to specify which of the matching elements to get by its index number. Example 1: This example uses 1 min read How to Refresh a Page using jQuery? Refreshing a page using jQuery allows you to programmatically reload the current webpage, ensuring updated content or resetting the page's state. It can be done using location.reload() method.Table of ContentUsing location.reload() MethodUsing history.go(0)Using location.replace() with Current PageR 3 min read Like