Thomas
Thomas

Reputation: 157

Custom CSS cursor using JQuery css method

Is there a way I can use JQuery's .css() method to give the following cursor style?:

cursor: url(http://www.google.com/intl/en_ALL/mapfiles/closedhand.cur), default !important;

Upvotes: 4

Views: 5806

Answers (2)

Amy
Amy

Reputation: 7466

jQuery doesn't understand the !important, so if you remove that it'll work:

$('selector').css({
    'cursor': 'url(http://www.google.com/intl/en_ALL/mapfiles/closedhand.cur), default'}); 

There are ways to get around it, why not use a CSS class?

/* CSS */
.cursor {
    cursor: url('http://www.google.com/intl/en_ALL/mapfiles/closedhand.cur'), default !important;
}

So you can just:

$('selector').addClass('cursor');

There are other alternatives too, see: How to apply !important using .css()?

Upvotes: 6

dev
dev

Reputation: 4009

It seems to work fine for me in a fiddle using the below code, but yes as mentioned above I removed the !important which made it work.

$('#cursor').css(        
    'cursor','url(http://www.google.com/intl/en_ALL/mapfiles/closedhand.cur),default'
);

Upvotes: 1

Related Questions