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

93
Views
Insertar texto en div editable cuando se hace clic en otro div

Tengo un div editable y quiero insertar texto cuando se hace clic en otro div , usando document.execCommand . Cuando uso un button , funciona correctamente, pero no funciona cuando se usa un div en el que se puede hacer clic.

 <!-- When I click this, it works --> <button on:click={e => document.execCommand("insertText", false, "Some text")}>Inser text</button> <!-- When I click this, it doesn't --> <div on:click={e => document.execCommand("insertText", false, "Some text")}>Inser text</div> <div contenteditable="true" />

Sospecho que es un problema de enfoque. He intentado llamar a e.preventDefault() pero tampoco funciona.

No es relevante, pero estoy usando Svelte.

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

0

Encontré una solución en este post .

Básicamente, se debe usar el evento mousedown , en lugar de click .

En mi caso, se ve así:

 <div on:mousedown={e => { e.preventDefault(); document.execCommand("insertText", false, "Some text"); }>Inser text</div>
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!