Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda