Why doesnt this code work? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Why doesnt this code work?

div.appendChild(document.createElement("p").appendChild(document.createTextNode("Hello World"))); It technically works but not as intended. The problem is that when it outputs a p element with a text node it doesnt render the p css styles and is inline instead of a block

22nd Mar 2017, 5:34 PM
YourDamnSandwitch
YourDamnSandwitch - avatar
2 Antworten
0
It may be running too early...try putting it in a function function change(){ div.appendChild(document.createElement("p").appendChild(document.createTextNode("Hello World"))); } then calling the function on window load window.onload = change();
22nd Mar 2017, 5:57 PM
Garan Weber
Garan Weber - avatar
0
+Garan Weber That part was just a snippet. Originally I had: <script> window.onload = function() { //Some Code function output(input) { cnsl.appendChild(document.createElement("p").appendChild(document.createTextNode(input)));} //Some Code output("Hello World"); } <script> <style> p { background-color: blue;} <style> Some HTML
22nd Mar 2017, 6:16 PM
YourDamnSandwitch
YourDamnSandwitch - avatar