Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have a problem to hide div using java script plz help me my ssample code is as
XML
<script type ="text/javascript" language ="javascript" >
function hideDiv()
{
var divs = document.getElementById ("treelist");
//divs.disabled =false ;
//divs.visible=true;
divs .setAttribute ('visible','true' );

}
</script>


and div is as
XML
<div id= "treelist" visible ="false"  runat ="server"  >
        <asp:TreeView ID="tvDept" runat="server" BorderStyle="Solid" Width="156px"
          >
            <Nodes>
                <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
                <asp:TreeNode Text="New Node" Value="New Node">
                    <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
                </asp:TreeNode>
                <asp:TreeNode Text="New Node" Value="New Node">
                    <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
                </asp:TreeNode>
                <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
            </Nodes>
        </asp:TreeView>
    </div>
Posted
Updated 27-Jun-10 20:45pm
v2
Comments
Sandeep Mewara 28-Jun-10 2:59am    
Posted a comment to your follow up question.

1 solution

yogeshptl wrote:


You used an attribute 'visible' here. If you use that and set it to false then it would not be present in the page anymore and thus Javascript wont be able to find it.

Instead use 'display' attribute.
XML
<div style="display:none">


This will keep the control on page and accessible in Javascript.

For toggling the value of display try:
JavaScript
var divs = document.getElementById ("treelist");
// to show
divs.style.display = "block";
// to hide
divs.style.display = "none";
 
Share this answer
 
v2
Comments
Yogesh M Patil 28-Jun-10 2:53am    
thanks Sandeep for replay, but this code not work.
Sandeep Mewara 28-Jun-10 2:59am    
What do you mean it doesn't work.
Remove the runat=server tag from div and try. You must be using this in a master page/content page where the Id won't be treelist in JS.

If it doesnt work, debug and see what issue/error you get.
What i told is correct and should work.
Yogesh M Patil 28-Jun-10 3:20am    
thank i remove the runat tag its work fine . thank you again.

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