jQuery remove hash from URL

If you have issues with jQuery adding # to the end of URLs , which normally happens when you have jQuery actions tied to links - such as below

<a href='#' class="your-class">Show Locations</a>

To make jQuery not append # to the end of the current URL use the preventDefault() function - see below for an example

$('.your-class a').click( function(event){

        // stop the click on the link adding a # to the end of the 

        // do other stuff


Now when the Show Locations link is clicked a # will not be added to the current URL

Refer http://developer.mozilla.org/en-US/docs/DOM/event.preventDefault for more info

Justin Kelly

Justin Kelly

Web Developer, Business Analytics, Data Engineer specialising in PHP and Tableau

Based in Melbourne, Australia

Feel free to contact me justin@kelly.org.au or _justin_kelly

Leave a comment

Notify me of replies by email.