Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
Creating a highlighter for Chrome Extension

I want to create a highlighter feature for my Chrome extension. I am not sure what is wrong with my code, I am using Javascript. The code is below. Note - I am using the attribute as a substitute for highlighting, it's not permanent.

function getText() {
 if (document.getSelection) {
    return document.getSelection().toString();
 } else {
    if (document.selection) {
        var text2 = document.selection.createRange();
    }
  }
}
function replaceText() {
  let tex = getText();
  if (document.getSelection) {
     alert("hi");
     document.getSelection().innerHTML = document.getSelection().replace(tex, "<u>" + 
     tex + "</u>");
  } else {
    if (document.selection) {
        document.Selection().createRange().innerHTML = tex.replace(tex, "<u>" + tex + " 
        <u>");
        alert("hello");
    }
}
    alert(tex);
}

let btn = document.createElement("button");
btn.innerHTML = "Highlight";
btn.onclick = function () {
replaceText();
};
document.body.appendChild(btn);

[Better view of the Code] 1

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda