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

231
Vistas
Applying CSS to only certain lines in textarea

I have a textarea that needs green color for the line that begins with double slash(//).

<textarea id="code-init" spellcheck="false"></textarea>

now I have used following code to attempt what I thought,

document.getElementById("code-init").onkeyup = e => {

if(e.key === '/') {
    console.log(e.key)
    document.getElementById("code-init").onkeyup = e =>{
        if(e.key === '/')
            e.target.style.color = "green"
        document.getElementById("code-init").onkeyup = e =>{
            if(e.key === "Enter")
                e.target.style.color = "white"
         }
     }
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could simulate an div and insert each letter as span. Callback and check if they include // then traverse the characters to define "a line" and color the spans of the "line"? http://jsbin.com/qinacusuzo/edit?html,output

Or use linear gradient to color the background of the textarea: https://jsfiddle.net/c6hzg08d/

A hard task, maybe worth looking for libraries that help you achieve this.

about 4 years ago · Juan Pablo Isaza Denunciar
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