/    Sign up×
Community /Pin to ProfileBookmark

get current cursor style

How do I get the current cursor style no matter what element I am over. I need the style of pointer to detect when to do something or not.

Thanks for the help

to post a comment
JavaScript

17 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisNov 07.2006 — You could try to use the mousemove event. In IE, event.srcElement.style.cursor might work.
Copy linkTweet thisAlerts:
@thechasboiauthorNov 07.2006 — I need to get the cursor based upon an onclick event and depending upon which cursor is there is whether the function is called. Thanks for the reply
Copy linkTweet thisAlerts:
@thechasboiauthorNov 07.2006 — Is theresome one that has an idea what I mean.

Thanks for the reply
Copy linkTweet thisAlerts:
@gil_davisNov 08.2006 — Sorry, I thought you had it figured out. You can get the information from any event using what I posted.
Copy linkTweet thisAlerts:
@thechasboiauthorNov 08.2006 — gil davis

Thanks for the suggestion but it is not working or I am missing something in the implimentation. I am currently testing it like this. I am adding an onclick event to a function that alerts the line of code you provided. The only thing I get from either passing the id or just verbatum is an empty alert. Thanks for the reply.
[code]
function getCursor(id){
//alert(event.id.style.cursor);
alert(event.srcElement.style.cursor);
}
[code]
Copy linkTweet thisAlerts:
@gil_davisNov 08.2006 — What browser are you using? How are you attaching the function?
Copy linkTweet thisAlerts:
@thechasboiauthorNov 08.2006 — onclick="" is how I am using the function to call the event. I am using IE and FF and safari as well. I need this to be an all around fix multibrowser if you will. Thanks Gil.
Copy linkTweet thisAlerts:
@gil_davisNov 08.2006 — Let's do something basic so that you can see that it can work.
<img src="redstarf.gif" onclick="alert(this.style.cursor)" style="cursor:wait">
Copy linkTweet thisAlerts:
@thechasboiauthorNov 08.2006 — gil davis

OK, I think my problem is not being communicated well sorry. I have this function that seems to attach itself to my elements or in this case they are actually javascript objects. The function is a prototype and is called on a ondblclick event but some times it is called other ways. This function is added through the add event handler "addEventListener" to the object. The elements on the page are all objects with the same attached functions. OK, I hope that makes sense. I call the function other places on other events but do not use the "addEventListener" event to attach the function. I can not just use "addEventListener" because it is sometimes called from a pop up window and there for really can not be attached or can it and would that be smart. I do not want to attach this event every where and loose the capability of this function. My idea was to keep track of the cursor because the function should be allowed to "unfreeze" if certain cursors are displayed. I hope this makes sense.

Thanks for the reply.
Copy linkTweet thisAlerts:
@gil_davisNov 08.2006 — I hope this makes sense.[/quote]Nope, you lost me. Maybe someone else will pick it up.
Copy linkTweet thisAlerts:
@thechasboiauthorNov 08.2006 — Well I will reask the question. Is there a way to get the current cursor style from the document itself or the body of the page? This is what I am thinking is the easiest fix for this problem until I find the proper solution. Thanks for the answer.
Copy linkTweet thisAlerts:
@gil_davisNov 08.2006 — I am beginning to think that my definition of cursor style is not the same as yours. What is your native language?
Copy linkTweet thisAlerts:
@thechasboiauthorNov 08.2006 — gil

I am using ASP with loads of javascript. The function in question is a javascript function. OK, I will try again and see if I make sense. I have this app you dbclick an element a function takes control of that object, the cursor is "move" but when you move off it is something else either pointer, default or what ever. I would like to know if the pointer is not "move". In needing this data I need to figure out how to get the current cursor no matter which object the mouse is over. I hope this clears things up a bit.
Copy linkTweet thisAlerts:
@gil_davisNov 08.2006 — The purpose of the cursor style is to change it from the system default to something else while the mouse hovers over the object. You cannot discover the actual system state of the mouse pointer (i.e.: the "cursor") as it moves over different objects using javascript unless the property has been previously set by either CSS or javascript.

What I meant was "what language do you speak", not what you are writing in.
Copy linkTweet thisAlerts:
@thechasboiauthorNov 08.2006 — I am born and raised in Ohio USA English is the native language
Copy linkTweet thisAlerts:
@gil_davisNov 08.2006 — To show you what I mean, I have created a demo page that uses mousemove to display the cursor style in the window status. You can access it at http://components.patton.com/gil/test56.htm. The only thing that has a cursor style assigned is the red star in the corner.
Copy linkTweet thisAlerts:
@thechasboiauthorNov 08.2006 — gil davis

I have done this many time on the site but I thank you for the effort and all the posts. I am trying twnety different ways to get this to work correctly like daily it is driving me nuts. Again thanks for the posts and all the help including the example page.
×

Success!

Help @thechasboi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...