Create new <p class="demo"> with Javascript | Sololearn: Learn to code for FREE!


Create new <p class="demo"> with Javascript

So I'm working on a button that creates more <p> with changing text and I can make a new paragraph and text node and add them to a div I made but I need to give it a class for it to work and newpp.class="demo" doesn't work (newpp is the new paragraph and newText is the new text node). Can someone help?

8/24/2018 3:17:38 AM

Marvin Lee

3 Answers

New Answer


newpp.setAttribute("class", "demo"); This will add the class Attribute to your paragraph with the value "demo". Next time just looking in the Mozilla Docs or google it, that can save much time for you 😉


Ah thanks Herobrine


A better option might be newpp.classList.add("demo")