How to get the current page url using jQuery

  1291 views   2 years ago jQuery

Use the syntax $(location).attr("href");

You can use the Location object and jQuery attr() method to get the URL of the current page.

Let's take a look at an example to understand how it actually works:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>jQuery Get Current Page URL</title>
<script src=""></script>
            var pageURL = $(location).attr("href");
    <button type="button">Get URL</button>


Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]