Search code examples
javascriptcssmouse-cursor

How to check if a cursor style is supported


How can I check, with JavaScript, whether cursor:none is supported?


Solution

  • Simply create an element, set the property, and check whether the property is still existent.

    function isCursorNoneSupported() {
        var a = document.createElement("a");
        a.style.cursor = "none";
        return a.style.cursor === 'none';
    }
    
    if ( isCursorNoneSupported() ) {
        alert("cursor:none is supported!");
    } else {
        alert("cursor:none is not supported :(");
    }
    

    To check which browsers support cursor:none, have a look at: cursor Browser compatibility