javascriptbookmarkletbookmarks

if statement in a bookmarklet not working


I made a bookmarklet for people in my school. Here is the code: document.body.contentEditable=true; there is also another bookmarklet to turn it off: document.body.contentEditable=false; These worked, but I wanted to try to make them into one bookmarklet. I tried this and failed. Here is the code: if (document.body.contentEditable == true) { document.contentEditable = false; } else { document.body.contentEditable = true; } I have no clue why it does not work. Someone please help.


Solution

  • This is a simpler way to do it:

    javascript: (function () {
      const body = document.body;
      body.contentEditable = !body.isContentEditable;
    })();