+ 1

How to style some appended text on page

pls how do i style appended stuffs on a page using javascript i tried using (classList and the .style method but its not working)

13th Feb 2022, 7:41 PM
Okere Samuel
Okere Samuel - avatar
5 Respuestas
+ 1
Ex: var x = document.getElementById("#id"); //get element //add style : x.style.color = '#6600FF'; x.style.width = '100px'; edit: show us the code. wrap all js cide in : onload = () => { // js code here };
13th Feb 2022, 8:18 PM
Jayakrishna 🇮🇳
+ 1
window.onload=()=>{ var h = document.createElement("h1") h.innerHTML="Hello" h.style.color="red" document.body.appendChild(h) }
13th Feb 2022, 8:52 PM
Chigozie Anyaeji 🇳🇬
Chigozie Anyaeji 🇳🇬 - avatar
+ 1
Thanks jayakrishna and chigozie i tried that method it works but what i was actually trying to do is if i could be able to createElement like a div using js then create another element which is an anchor tags then append those anchor tags in that div and then append the div on my page and then style that div and anchor tags using js only . THIS IS MY JS CODES window.onload=()=>{ let contain = document.querySelector("#box") let words = document.createElement("a") words.innerHTML="Home" let wthree = document.createElement("a") wthree.innerHTML="About" let wfour = document.createElement("a") wfour.innerHTML="Contact" contain.append(words,wthree,wfour) }
13th Feb 2022, 10:00 PM
Okere Samuel
Okere Samuel - avatar
+ 1
Okere Samuel you can also add class and id to elements you create and than select this class/id in css like you normaly do
13th Feb 2022, 10:49 PM
PanicS
PanicS - avatar