Basic jQuery question:
I am trying to reveal a div
that has been marked as hidden using jQuery. But am not quite getting it
I've created a JSFiddle here: http://jsfiddle.net/VwjxJ/
Basically, I want to use style="visibility: hidden;"
rather than style="display: none;"
as I want the space of the hidden element to be maintained
Have tried using show()
, fadeIn()
etc but neither work (they do for style="display: none;"
)
what am I doing wrong?
Answer: Use the jQuery :visible Selector You can use the jQuery :visible selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden; or opacity: 0; , because they preserve space in the layout even they are not visible to the eye.
The show() Method in jQuery is used to display the hidden and selected elements. Note: This method display the hidden elements which are using CSS display: none property. The elements are not visible whose visibility is hidden.
Syntax: $(selector). hide(speed,callback);
If you have hidden it with visibility:hidden
then you can show it with jQuery by
$(".Deposit").css('visibility', 'visible');
And in the fiddle you are missing jQuery. Here is a demo: http://jsfiddle.net/9Z6nt/20/
According to JQuery documentation .show()
"is roughly equivalent to calling .css('display', 'block')
, except that the display property is restored to whatever it was initially." Set the style explicitly instead. You could use a CSS class
.hidden{ visibility: hidden; } .shown{ visibility: visible; }
and set is using
$("#yourdiv").removeClass("hidden").addClass("shown");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With