How to get current URL in JQuery?
If you are using jQuery and would like to get the current URL, then you can use the following code
If you notice, in jQuery too, we need to access the “location” object in order to get the current URL. Once we access the location object, we use the “attr” or “prop” API to get the “href” attribute’s value.
However, I would suggest that it’s better to use window.location.href as it would be comparatively faster and simpler too.