4

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;

2 Answers 2

6

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()?

Sign up to request clarification or add additional context in comments.

2 Comments

I'm using JQuery UI Sortable which takes a cursor option and sets the cursor style using .css(). I've tried handling cursor changing with mouse events but have ran into trouble of resetting the cursor. Using the library's cursor option give me the expected cursor resetting.
If you use the <a> element, then you can do this in CSS a:hover{ cursor: .... } and get around not using JavaScript at all.
1

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'
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.