Samantha J T Star
Samantha J T Star

Reputation: 32848

How can I change my cursor with jQuery?

I just had an answer on how to do this:

CSS

body.ajaxloading {     cursor:wait; } 

jQuery

function enableLoadingIcon() {     
   $(body).addClass('ajaxloading'); 
} 
function disableLoadingIcon() {     
   $(body).addClass('ajaxloading'); 
} 

However when I try to implement it doesn't seem to work. Can anyone see what the reason is ?

Upvotes: 1

Views: 188

Answers (3)

Martin.
Martin.

Reputation: 10539

$(body) is wrong. It is actually $("body").

function enableLoadingIcon() {     
   $('body').addClass('ajaxloading'); 
} 
function disableLoadingIcon() {     
   $('body').removeClass('ajaxloading'); 
} 

or, even faster, $(document.body)

function enableLoadingIcon() {     
   $(document.body).addClass('ajaxloading'); 
} 
function disableLoadingIcon() {     
   $(document.body).removeClass('ajaxloading'); 
} 

Upvotes: 3

alexdlaird
alexdlaird

Reputation: 1293

Alternatively, you wouldn't have to declare the class in your CSS if you just manually injected the CSS using jQuery like so:

function enableLoadingIcon() {     
   $(document.body).css ("cursor", "wait"); 
} 
function disableLoadingIcon() {     
   $(document.body).css("cursor", "auto"); 
}

Upvotes: 0

Milimetric
Milimetric

Reputation: 13549

You just need $('body') instead of $(body)

Upvotes: 0

Related Questions