Jquery – Create Link Button with JQuery


I'd like to use JQuery to create a link button, but the code I wrote below doesn't seem to work. What is missing?

        <title>Click Url</title>
        <script src="http://code.jquery.com/jquery-latest.js"     
            <script type="text/javascript">
                $(function() {
                    $("#Button1").click(function() {
    <a href="http://google.com" id="an1">Click</a>
    <input id="Button1" type="button" value="button" />

Best Solution

The click() method will not work on hyperlinks. Instead of $("#an1").click(); to redirect to that URL, use this:

window.location.href = 'http://google.com';

Or, as suggested by davidsleeps in the comments, do this:

window.location.href = $("#an1").attr("href");