Simulate the user clicking on a link

Posted by timkl on Stack Overflow See other posts from Stack Overflow or by timkl
Published on 2010-04-18T21:58:30Z Indexed on 2010/04/18 22:03 UTC
Read the original article Hit count: 313

Filed under:
|

I want a link to be clicked when a key is pressed, I cooked up this jQuery:

   $('form#form1').bind("keypress", function(e){
        if(e.keycode == 13 || e.keyChar == 13 || e.which == 13){
        $('.LoginBoxButton a').click();
        }   
    });

It doesn't work, and I've read the following explaining why:

It's important to remember that click() will not trigger the default behavior on a link, even if nothing else is preventing it. So you can't use click() by itself to simulate the user clicking on a link and being taken to another url.

But how DO you simulate the user clicking on a link and being taken to another url?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript