0

How do I do innerHTML

I want HP to change but I can't figure out innerHTML

21st Feb 2023, 11:46 AM
Paxton Programer
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
21st Feb 2023, 1:40 PM
PanicS
PanicS - avatar
+ 2
Please show your code.
21st Feb 2023, 12:16 PM
Lisa
Lisa - avatar
+ 1
R o s h a a n and PanicS - thank you
22nd Feb 2023, 6:13 PM
Paxton Programer
0
Gadora
23rd Feb 2023, 10:05 AM
Any videos
Any videos - avatar