+ 3

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?

24th Aug 2018, 3:17 AM
Marvin Lee
Marvin Lee - avatar
3 Respuestas
0
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 😉
24th Aug 2018, 4:51 AM
BraveHornet
BraveHornet - avatar
+ 1
Ah thanks Herobrine
24th Aug 2018, 4:53 AM
Marvin Lee
Marvin Lee - avatar
0
A better option might be newpp.classList.add("demo")
25th Aug 2018, 1:44 PM
Murali Krishnan A