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

131
Vistas
How to post a paragraph in HTML with CSS styling applied?

I am using the following code to print a paragraph when the button is clicked:

document.querySelector('button')
  .addEventListener('click', function() {
     const p = document.createElement('p');
     p.id    = "text";
    
    const val = document.getElementById('forminput').value;
    if (val.length) {
      p.innerHTML = val;
      document.querySelector('div').appendChild(p);
    }
});

When the paragraph is posted, I want it to retain the same CSS styling as well as the same onclick function as the

styling and function I use for other content.

What would be the right way to do it?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you have some styling set up for your p tags already, then this would automatically apply when you render the new p tag.

Else you can create a custom css class that holds the styling you're wanting to apply, and then add this classList to your newly rendered p tag as follows:

const p = document.createElement('p');
p.classList.add('your-class');
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