Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call jQuery function onclick?

I am using this code to get the current url of the page in to div, when I click on submit button. I am not getting how to call function onclick. How to do this?

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>localhost</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
        <script type="text/javascript">
            $(function () {
                var url = $(location).attr('href');
                $('#spn_url').html('<strong>' + url + '</strong>');
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div id="spn_url"></div>
            <input type="submit" value="submit" name="submit">
        </form>
    </body>
</html>
like image 840
milano Avatar asked Feb 12 '26 12:02

milano


1 Answers

Please have a look at http://jsfiddle.net/2dJAN/59/

$("#submit").click(function () {
var url = $(location).attr('href');
$('#spn_url').html('<strong>' + url + '</strong>');
});
like image 167
vinothini Avatar answered Feb 15 '26 00:02

vinothini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!