Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery show() for Twitter Bootstrap css class hidden

I'm using Twitter Bootstrap and I notice that jQuery show() or fadeIn() doesn't make DOM element marked with class hidden appear because the jQuery functions only remove the display: none specification. However, the visibility is still set to hidden.

I wonder what is the best possible way to work around this?

  1. Remove the hidden class on the element
  2. Change the visibility property
  3. Overwrite the hidden class in my own css

In particular, I want to know whether fixing this with jQuery or css is better and why.

like image 958
Lim H. Avatar asked Jan 30 '13 17:01

Lim H.


People also ask

Is show or hide in jQuery?

The optional speed parameter specifies the speed of the hiding/showing, and can take the following values: "slow", "fast", or milliseconds. The optional callback parameter is a function to be executed after the hide() or show() method completes (you will learn more about callback functions in a later chapter).

What does jQuery hide () do?

jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To show hidden elements, look at the show() method.

How can show hide div on button click in bootstrap?

You need to make sure the target div has an ID. Bootstrap has a class "collapse", this will hide your block by default. If you want your div to be collapsible AND be shown by default you need to add "in" class to the collapse. Otherwise the toggle behavior will not work properly.

How do I hide a div but keep the space?

The visibility: hidden rule, on the other hand, hides an element, but the element will still take up space on the web page. If you want to hide an element but keep that element's space on the web page, using the visibility: hidden; rule is best.


2 Answers

The css class you're looking for is .collapse. This sets the element to display: none;

So using $('#myelement').show() will work properly.

UPDATE : Bootstrap v3.3.6 has updated .collapse back to:

.collapse {   display: none; } 
like image 104
Eoinii Avatar answered Sep 20 '22 00:09

Eoinii


This will fade your invisible element in and remove the class

$('#element.hidden').css('visibility','visible').hide().fadeIn().removeClass('hidden'); 

http://jsfiddle.net/7qxVL/

If you don't really need the element to be invisible (ie take up the space) tho you might wanna redefine .hidden (in you local css, don't change bootstrap source, or even better, in your local LESS file).

like image 25
David Fregoli Avatar answered Sep 18 '22 00:09

David Fregoli