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
2 Réponses
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();
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