Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting mouse cursor type change in a webpage

Is there any event which is triggered when the mouse cursor changes as it hovers over different page elements ?

Ideally an event like this:

window.onmousecursorchange = function(e) {
    // e would contain information about the cursor
    // eg. e.type could contain 'text','pointer', etc..
}

Note: The solution should not involve jQuery or other libraries

Update:

The 'possible duplicate' question is tagged with jQuery infact all the answers (none of which solve the problem) are based on jQuery. I am looking for a pure JavaScript solution. If the moderators believe this is not enough reason to keep this question open feel free to close.

like image 831
lostsource Avatar asked Jan 26 '13 17:01

lostsource


People also ask

How do I change the cursor type in HTML?

You can simply use the CSS cursor property with the value pointer to change the cursor into a hand pointer while hover over any element and not just hyperlink. In the following example when you place the cursor over the list item, it will change into a hand pointer instead of the default text selection cursor.

How does your cursor change when you hover over a link?

By default, the mouse pointer is an arrow. When you hover over text you get the I-beam cursor, whereas the pointer changes to a hand cursor when the mouse is over a hyperlink.

What is Pointerpointer?

A pointer to a pointer is a form of multiple indirection, or a chain of pointers. Normally, a pointer contains the address of a variable. When we define a pointer to a pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value as shown below.


2 Answers

You can try this:

document.addEventListener('mouseover',function(e){
    var cursor = e.target.style.cursor;
    console.log(cursor);
});

It uses event bubbling to increase performance and save code.

like image 101
Licson Avatar answered Sep 23 '22 23:09

Licson


Yes with event onmouseenter

$('*').mouseenter(function(){
    var currentCursor = $(this).css('cursor') ;
    console.log( currentCursor );
});
like image 44
Hary Avatar answered Sep 20 '22 23:09

Hary