Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!