Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Show not working if css class has display:none

Tags:

html

jquery

css

I have a class called loading like this:

.loading {
   display: none;
   vertical-align: top; 
   margin: 0; 
   padding: 0; 
   background: url('../images/shared/loading_16x16.gif') center center no-repeat; 
   width: 16px; 
   height: 16px;
}

with following html snippet:

<div id="loading" class="loading"></div>

and my jQuery code (on document ready):

$.ajaxSetup({
    beforeSend: function () {
        $("#loading").show().children().show();
    },
    complete: function () {
        $("#loading").hide().children().hide();
    }
});

But show() is not working at all. Even if I trigger it from the chrome developer window. On the chrome developer window if I uncheck the display: none from the loading class then the tag appears.

What's happening?

like image 765
Phoenix_uy Avatar asked Nov 18 '13 13:11

Phoenix_uy


People also ask

How do I use display none in CSS?

The default display value for most elements is block or inline . This panel contains a <div> element, which is hidden by default ( display: none ). It is styled with CSS, and we use JavaScript to show it (change it to ( display: block ).

What does show () do in jQuery?

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.

Does display none affect DOM?

display: none; does not remove or in anyway affect an element's DOM representation.


1 Answers

I just figured out!

I fix it by doing this on my jQuery:

$.ajaxSetup({
     beforeSend: function () {
         $("#loading.loading").show();
     },
     complete: function () {
         $("#loading.loading").hide();
     }
});

Hope helps to some else :)

like image 181
Phoenix_uy Avatar answered Sep 18 '22 13:09

Phoenix_uy