I'm working on a web application that uses onHashChange
event listener in some situations and manually clicking on a link with href="#hash"
works perfectly well.
But when I trigger click on the same link using jQuery's $('a[href=#"hash"]').trigger('click')
or $('a[href=#"hash"]').click()
hash in address bar is not changing.
Is it something that I'm doing wrong? or I shoud use another method for this purpose?
HTML
<a href="#hash">Do Something</a>
JS
// Not working
$('a[href="#hash"]').click();
// Not working
$('a[href="#hash"]').trigger('click');
preventDefault()
in your click handler? – Latashialatch