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

213
Views
Script solo cambiando document.body.contentEditable a falso y no verdadero
javascript:if(document.body.contentEditable == false){document.body.contentEditable = true;}else{document.body.contentEditable = false;} void 0;

parece que todo lo que hace es hacerlo falso.

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

0

Dado que contenteditable es un atributo de element , es mejor leerlo, establecerlo o modificarlo utilizando las propiedades .getAttribute y .setAttribute del objeto del elemento.

El fragmento muestra la sintaxis utilizada para leer y establecer el atributo, utilizando un ejemplo de trabajo en el que un botón alterna la editabilidad de un elemento de párrafo.

 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

La razón por la que siempre lo cambia a falso es principalmente porque document.body.contentEditable va a ser una cadena (es decir, "true" , "false" , "inherit" ). Su código solo necesita incluir comillas sobre true y false en su condicional para que funcione según lo previsto:

 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!