Function still executes "if" even though the condtions aren't met (Javascript)

Viewed 34

I have this function attached to an input:

    function keyIcon1Action()
    {
        if (document.body.style.cursor != 'url(keyCursor1.png)')
        {
            document.body.style.cursor = 'url("keyCursor1.png"), auto';
            menuText.innerHTML = "Vieille clé";
            menuText.style.visibility = "visible";
            keyIcon1.style.opacity = "0.34";
        }
        else
        {
            document.body.style.cursor = "default";
            menuText.style.visibility = "hidden";
            menuText.innerHTML = "";
            keyIcon1.style.opacity = "1";
        }

It should make the cursor a custom png if the cursor is not the custom png. If the cursor is already the png, then it should return to the default cursor. Unfortunately, when the function has already been executed once, and the cursor is the custom png, the function still goes to "if".

I've tried the opposite but it still won't work. I can't find much on the Internet because the cursor stuff is so uncommon.

0 Answers
Related