Now there are quite a few similar questions here, but I was wondering what should I do if I want to not just change the location window, but call any functions that can be attached to click and change only href if they are ok with it, or just redirect if there are no listeners.
For instance:
var a = $('.edithost'); a.click(function() {return false;});
Should I click the link with the mouse, this will never lead me to href, so just redirecting the user to attr('href') will change the intended behavior of the page. In addition, the click applies not only to links, but also, say, to buttons, in which case I will need to submit a form, etc.
So, I was wondering if it is possible to emulate a click on an element so that the entire behavior of the browser is exactly the same as if it was clicked on by the mouse?
There cannot be listeners bound to a link.
Example:
var a = $('<a href="google.com">google</a>'); a.click(); a.trigger('click');
This will not lead you to Google, I want to do this.
Update: .click() will not work. trigger('click') too. preventDefault has nothing to do with this
source share