views:

431

answers:

2

hi my dear friends ...

How can I change the visibility of a control with jQuery? I have a control that its visible property to false...(not css)

When I used show() function for it nothing happened, it seems that hide() and show() methods are for css set of a control , not visible property...

Thanks for your answers,

Best regards

+3  A: 

You can't do this with jQuery, visible="false" in asp.net means the control isn't rendered into the page. If you want the control to go to the client, you need to do style="display: none;" so it's actually in the HTML, otherwise there's literally nothing for the client to show, since the element wasn't in the HTML your server sent.

If you remove the visible attribute and add the style attribute you can then use jQuery to show it, like this:

$("#elementID").show();

Old Answer (before patrick's catch)

To change visibility, you need to use .css(), like this:

$("#elem").css('visibility', 'visible');

Unless you need to have the element occupy page space though, use display: none; instead of visibility: hidden; in your CSS, then just do:

$("#elem").show();

The .show() and .hide() functions deal with display instead of visibility, like most of the jQuery functions :)

Nick Craver
@Nick - The OP stated "(not css)". I can't imagine what that means, though.
patrick dw
@patrick - Ohhhhh, that's an ASP.Net thing, totally different answer, I'll update.
Nick Craver
that is very very bad for me .....imagine that i have two buttons next together and when one of them is invisible (from codebehind)so the other one can fill it's space and this is exactly what i want....i forced to invisible that button for some conditions and also forced to visible it with jquery and invisible the other one with jquery....so with css -> hidden control i have white space ... how can i fill it by visible button???however really really thanks for your attention and your answer//best regards/....
LostLord
@LostLord - That's the part of the answer covering `display`, if you use `display: none;` instead of `visibility: hidden;`, then it won't occupy any space in the page while hidden.
Nick Craver
+1  A: 

.show() and .hide() modify the css display rule. I think you want:

$(selector).css('visibility', 'hidden'); // Hide element
$(selector).css('visibility', 'visible'); // Show element
Harold1983-
that is very very bad for me ..... imagine that i have two buttons next together and when one of them is invisible (from codebehind)so the other one can fill it's space and this is exactly what i want.... i forced to invisible that button for some conditions and also forced to visible it with jquery and invisible the other one with jquery.... so with css -> hidden control i have white space ... how can i fill it by visible button??? however really really thanks for your attention and your answer// best regards/....
LostLord