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

316
Views
Cambiar permanentemente el color de fondo del texto seleccionado

¿Cómo puedo cambiar permanentemente el color de fondo del texto DIV cuando lo selecciono? Lo que estoy tratando de lograr es un efecto de resaltado como este: ingrese la descripción de la imagen aquí

¿Alguien puede indicarme cómo lograr esto con javascript?

Agradezco mucho tu ayuda.

EDITAR: necesito que mi texto permanezca resaltado y resalte varios textos sin perder el resaltado de los anteriores.

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

0

Debe agregar un detector de eventos en javascript y cuando se selecciona un texto en ese momento, debe cambiar el color como se muestra a continuación.

 function logSelection(event) { // Get Selection sel = window.getSelection(); if (sel.rangeCount && sel.getRangeAt) { range = sel.getRangeAt(0); } // Set design mode to on document.designMode = "on"; if (range) { sel.removeAllRanges(); sel.addRange(range); } // Colorize text document.execCommand("ForeColor", false, "red"); // Set design mode to off document.designMode = "off"; } const input = document.querySelector('input'); input.addEventListener('select', logSelection);
about 4 years ago · Juan Pablo Isaza Report

0

Utilice ::selection para anular el color predeterminado:

 ::selection{ background: #FFD24D; }
 <p>A team of horses will struggle to chase down a spoken word.</p>

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!