0

I am having some problems with jQuery Variables. As I am kind of a newbie, maybe I am doing something wrong, but here it is:

var loading = jQuery('#loading');
        loading.hide();
        jQuery(document)
            .ajaxStart(function () {
                loading.show();
            })
            .ajaxStop(function () {
                loading.hide();
            });

What I am trying to do is, show my "loading" div while ajax is running, but the variable "loading" just seem to not work. If I use jQuery('#loading') everywhere instead of the variable it is working fine. What am I doing wrong?

1 Answers1

-1

jQuery and $. act differently. Try using $ for this job like:

$('document').ready(function(){
    var loading = $('#loading');
        loading.hide();
    $(document).ajaxStart(function(){loading.show()});
    $(document).ajaxStop(function(){loading.hide()});
});
Shah Quadri
  • 219
  • 1
  • 2
  • 11