Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Script only changing document.body.contentEditable to false and not true
javascript:if(document.body.contentEditable == false){document.body.contentEditable = true;}else{document.body.contentEditable = false;} void 0;

it appears that all it does is make it false.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Since contenteditable is an element attribute, it is best read, set, or changed, using the .getAttribute and .setAttribute properties of the element's object.

The snippet shows the syntax used to read and set the attribute, using a working example where a button toggles editability of a paragraph element.

let editBox = document.getElementById("edit-field");

document.getElementsByTagName('button')[0].addEventListener('click', event =>{

    if (editBox.getAttribute("contenteditable")=="true") {
    editBox.setAttribute("contenteditable", "false");
    console.log("switched to not editable");
  } else {
    editBox.setAttribute("contenteditable", "true");
    console.log("switched to editable");
  }
}) // end button click;
#edit-field {
  width: 300px;
  height: 100px;
  background: yellow;
}
<p id="edit-field" contenteditable="false"> I am editable (sometimes)</p>
<button>toggle editability </button>

about 4 years ago · Juan Pablo Isaza Report

0

The reason it is always changing it to false is primarily because document.body.contentEditable is going to be a string (i.e., "true", "false", "inherit"). Your code just needs to include quotes around true and false in your conditional for it to work as intended:

javascript:if(document.body.contentEditable == "false"){document.body.contentEditable = "true";}else{document.body.contentEditable = "false";} void 0;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!