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

220
Views
Seleccionar todo el texto en una celda de tabla en foco en Svelte o JS

Esta es más una pregunta de JS y HTML que esbelta.

Quiero seleccionar todo el texto en el campo cuando el elemento se enfoca. Funciona bien cuando el elemento es un elemento de entrada , pero no funciona con td . ¿Cómo puedo lograr esto con td (sin jQuery)?

 <script> function handleFocus(e) { e.target.select(); } </script> <input on:focus={handleFocus} value="Testing"/> <td on:focus={handleFocus} contenteditable="true">Testing</td>

REPL esbelto

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

0

Necesitas crear un rango de selección.

 <script> function handleFocus(e) { e.target.select(); } function tdFocus(e) { const el = e.target const range = document.createRange(); range.selectNodeContents(el); const sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range); } </script> <input on:focus={handleFocus} value="Testing"/> <td on:focus={tdFocus} contenteditable="true">Testing</td>

REPL esbelto

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!