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

263
Visualizações
How do I add text last in a text element in html via js

I want to add text last in a p element, not first, but i only know how to add last using +=

var pEL = document.querySelector("#text");
pEL.innerHTML += "1";
<p id="text">text</p>

now the p element says "text1" but i want "1text", how do i add something first in a text element?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0


pE1.innerHTML += "1";  

is simply shorthand for saying "the new html will be the old html + "1"

pEl.innerHTML = pEl.innerHTML + "1"

so instead, something like


pEL.innerHTML = "1" + pEl.innerHTML   

should do the trick.

about 4 years ago · Juan Pablo Isaza Relatório

0

The Element property innerHTML gets or sets the HTML or XML markup contained within the element so set it with concatenating 1 + the previous text (calling pEL.innerHTML without assignment is basiclly using the get to fetch the value)

var pEL = document.querySelector("#text");
pEL.innerHTML = "1" + pEL.innerHTML;
<p id="text">text</p> 

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