+ 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)
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
};
+ 1
window.onload=()=>{
var h = document.createElement("h1")
h.innerHTML="Hello"
h.style.color="red"
document.body.appendChild(h)
}
+ 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)
}
+ 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