Search code examples
javascriptdomcursor

Javascript change cursor icon to local icon.jpg


I am trying to change my cursor icon in a paint appliation using Javascript. The jpeg icon which I want to use for that purpose is saved locally. Can I use the following line to make this work?

document.body.style.cursor = "server/icon.jpg";

How could I make it work using a url alternatively?


Solution

  • Use the url property instead:

    document.body.style.cursor = "url('server/icon.jpg'), auto"
    

    You may want to check MDN for documentation related with cursor css.