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

259
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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