How to hide & show div elements with jquery (doesn't work in the second div)

I have two divs. I want to show one and hide the other based on a condition. My problem is that jquery only assigns the first div, I can tell by looking at the output of the web developer to confirm why?

if(!fd.getActiveXInstalled()) {
    $(".divActiveXdownloadButton").hide();
    $(".divActiveXNodownloadButton").show();  
} else {

    $(".divActiveXdownloadButton").show();
    $(".divActiveXNodownloadButton").hide();  
}

      

And the markup:

<div>
    <div class="divActiveXdownloadButton" style="display:none;">
        <asp:ImageButton ID="BtnDownload" runat="server" ></asp:ImageButton>
    </div>
    <div class="divActiveXNodownloadButton" style="display:none;">
        <asp:ImageButton ID="BtnReturn" runat="server"></asp:ImageButton>
    </div>
</div>

      

+2


source to share


3 answers


Oh, Spirit! I was executing my script before the second div was removed! I needed jscript right in the middle of my page to invoke a third party ActiveX control. I mistakenly added my jscript along with this to hide and show the controls. Unfortunately, some of these controls have not yet been saved. I moved the jscript part down and now it works.

Thanks to everyone who provided input.



James

0


source


Try hiding the contained elements, I don't know what <asp:ImageButton>

to include if they are input elements like image

:

if(!fd.getActiveXInstalled()) {
    $('.tdActiveXdownloadButton > input[type=image]').hide();
    $(".tdActiveXdownloadButton > input[type=image]").show();  
} else {    
    $(".tdActiveXdownloadButton > input[type=image]").show();
    $(".tdActiveXdownloadButton > input[type=image]").hide();  
}

      

or just try:



$('.tdActiveXdownloadButton').children().hide();

      

or

$('.tdActiveXdownloadButton > *').hide();

      

+2


source


You don't have to hide table cells at all, they are not meant to be used that way. Either put an element in the cell that you can hide, or don't use a table at all.

+1


source







All Articles