Reputation: 115
Not sure if it is weird or simply I am stupid, but I am having an issue in JavaScript innerHTML. Ok, I hve an empty DIV in my body tag. What I want is to write an unordered list in it. So, I made this:
<script>
var bla = document.getElementById("bla");
bla.innerHTML = "<ul><li>LOL</li></ul>";
</script>
<div id="bla">
</div>
Hmm nothing is appearing in the DIV.. :(
Upvotes: 0
Views: 812
Reputation: 2615
<div id="bla">
</div>
<script>
var bla = document.getElementById("bla");
bla.innerHTML = "<ul><li>LOL</li></ul>";
</script>
Upvotes: 0
Reputation: 5356
id='bla' was not found because you script above the id and not use any function
change like this
<div id="bla">
</div>
<script>
var bla = document.getElementById("bla");
bla.innerHTML = "<ul><li>LOL</li></ul>";
</script>
or
<script>
window.onload=function(){var bla = document.getElementById("bla");
bla.innerHTML = "<ul><li>LOL</li></ul>";
};
</script>
<div id="bla">
</div>
Upvotes: 3