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

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

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