Search code examples
jqueryasp.netshow-hideasp.net-placeholder

Hide/Show Placeholder using Jquery


I have a placeholder and want to show it using JQuery. Now in placeholder I cannot have style="Visibility:hidden" so I have to set the Visible Property to False, hence Jquery not able to find it.

My question is how do I set the visibility on JQuery load function instead, have tried following with no success(bare in mind my controls have this extra characters at beginning so need by ClientID):

 $('div[id*=phAdd]').hide();
 $('div[id$=phAdd]').hide();

Solution

  • The reason for this Placeholder not being found is because of this line

    `Visible="false"`
    

    while defining the ASP.NET control

    Visible="false" does not render the element in the First place. So you have no way of selecting it. Instead remove that line and add a Class to it which has the display property set.

    So by doing this the element will be available on the DOM and your selector should work fine.

    <asp:Placeholder runat="server" ClassName="hide" 
    

    CSS

    .hide{
        display: none;
    }