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.
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.
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.
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.
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.
Yes with event onmouseenter
$('*').mouseenter(function(){
var currentCursor = $(this).css('cursor') ;
console.log( currentCursor );
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With