Click here to Skip to main content
15,909,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help with this code jquery is not working instead of hiding the content upon button click it do nothing.Any suggestion


XML
<head runat="server">
    <title></title>
    <script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>

    <script type="text/javascript" >
        $(document).ready(function () {
            $("button").click(function () {
                $("p").hide();
            });
        });
</script>
</head><pre>

C#
<body>
    <form id="form1" runat="server">

    <h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>

    </form>
</body>
Posted
Updated 18-Jul-13 20:14pm
v2

C#
<head runat="server">
    <title></title>
    <script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
 
    <script type="text/javascript" >
        $(document).ready(function () {
            $('#<%=btn.ClientID%>').click(function (e) {
                $(".Para").hide();
                e.preventDefault();
            });
        });
</script>
</head>
<p class="Para">This is a paragraph.</p>
<p class="Para">This is another paragraph.</p>
<asp:button id="btn" text="Click Me" runat="Server" ></asp:button>
 
Share this answer
 
v2
Comments
aatish442000 19-Jul-13 2:25am    
Thanks
C#
<script type="text/javascript" >
        $(document).ready(function () {
            $("button").click(function () {
                $("p").hide();
        return false;
            });
        });
</script>

Or else use <input type="button"> , instead of <button>
 
Share this answer
 
v2
Have a look at this example to understand how it works.
<p id="yourcontent">This is an example of text that will be shown and hidden.</p>

<input type="button" value="Hide" onclick="$('#yourcontent').hide()" />

<input type="button" value="Show" onclick="$('#yourcontent').show()" />

Regards..:laugh:
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900