Click here to Skip to main content
15,896,540 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..

I get div id from a jquery function...& now i wanna hide this div in another jquery function onbutton click event...how to do this???
Posted

Hi
Try this code..

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery.js.js"></script>

    <script type="text/javascript">


        $(function () {

            $('#btnShow').click(function () { $('#divid').show('slow'); return false;  });
            $('#btnHide').click(function () { $('#divid').hide('slow'); return false; });



        })

    </script>
</head>
<body>
    <form id="form1" runat="server">

        <div id="divid" style="width: 100px; height: 100px; background-color: green"></div>
        <asp:Button ID="btnHide" runat="server" Text="Hide" />
        <asp:Button ID="btnShow" runat="server" Text="Show" />

    </form>
</body>
</html>
 
Share this answer
 
Add follwoing script to your head tag

JavaScript
<script type="text/javascript">
    $(document).ready(function () {
        $("#Button2").click(function () {
            var eID = document.getElementById("MyDiv");
            callit(eID);
        });
    });

    function callit(cid) {
        $(cid).hide();
    }
</script>



Put Following markup in head tag
XML
<div id="MyDiv">This is my div</div>
 <input id="Button2" type="button" value="button"  />
</div>


Note: Do not forget to add jquery link in your page

Hope This Helps!!!
 
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