tags:

views:

54

answers:

1

Hi,
For my application I want to trigger an anchor tag using the .click() event, which should redirect to page mention in href.i m using following code to achieve it.but its not working as expected.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title></title>
    <script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
    </head>
    <body>
    <script>
    $(function() {
        $('#upload').click(function(e) {
            e.preventDefault();
                $("#login_or_register").click();
        });
    });
    </script>
    <div id ='upload'>upload</div>
    <a  style ='display:none' href="abc.html" id="login_or_register">Login or register</a>
    </body>
    </html>

Help me out!!

+4  A: 

You are clicking the link, but that won't cause the browser to follow the link (the "default action" or behavior is what this is called), so instead of this:

$("#login_or_register").click();

You need this:

window.location.href = 'abc.html';
//or dynamically:
window.location.href = $("#login_or_register").attr('href');
Nick Craver