You should use classList, not setAttribute:
classList
setAttribute
const p = document.createElement('p'); p.classList.add("your-class"); // do whatever you need with the new p
Replace the your-class with the class that you need to add.
your-class