0
How do I do innerHTML
I want HP to change but I can't figure out innerHTML
4 Respostas
+ 3
To add to Roshaan explanation, if you create element via js, for example:
let el = document.createElement("div")
Then next line will set innerHTML
el.innerHTML = "any value"
By the way, innerHTML can be dangerous to use, because it allow embedding script tag, what can be used for bad things.
It is used to add html tags inside, but try to avoid using it.
To change text you can use element.innerText or
element.textContent
To add elements to parent use
element.appendChild(childElem)
Here is more about them and how to use them:
https://www.w3schools.com/jsref/prop_node_innertext.asp
And about dangerous side of innerHTML and why I recommend you to don't use it:
https://betterprogramming.pub/dom-manipulation-the-dangers-of-innerhtml-602f4119d905
And here is about appendChild in case you need it in your app:
https://www.w3schools.com/jsref/met_node_appendchild.asp
+ 2
Please show your code.
+ 1
R o s h a a n and PanicS - thank you
0
Gadora