tags:

views:

77

answers:

3

Hello,

I've tried the following code in my sample page and it doesn't work.All I'm trying to do is just append some text into a div on the page when the button is clicked.

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <script type="text/jscript">
        $(document).ready(function () {
            $('#Button1').click(function () {
                $('#testdiv').append("Hello World!!");
            });

        });

    </script>
    <input id="Button1" type="button" value="button" />
    <div id="testdiv"> 
    adiv
    </div>
</asp:Content>

Please guide me on how to get this simple thing to work in jquery...

Thanks

Edit:I updated my code as you suggested...still doesn't work...please help me...Thanks

A: 

You must use $('#Button1').click and not $('#Button1').ready

Andrea Zilio
I've edited my code as you have suggested...still doesn't work...
Josh
A: 

You're adding a handler to the button's ready event inside of the document's ready event. Since the button is already ready by the time you add the handler, nothing happens.

You need to add a handler to the button's click event, like this:

$('#Button1').click(function () {
    $('#testdiv').append("Hello World!!");
});
SLaks
I've edited my code as you have suggested...still doesn't work...
Josh
+2  A: 

Try fixing your script declaration from

<script type="text/jscript">

to

<script type="text/javascript">

as some browsers are finicky.

cballou
You got it!!! Thank you,....That was the final thing.
Josh