I have the following div:
<body>
<div id="div0" style="margin-top:5%;text-align:center">
One response will appear here
</div>
</body>
I have an array within script tags and would simply like to put the value of array[0]
into the div, to replace where it says "One response will appear here."
I am a bit confused as to what attribute of the div refers to this text - it is not innerHTML or .text
or .textContent
. Using any of these throws the error:
"Uncaught TypeError: Cannot set property 'innerHTML' of null"
EDIT:
This is where I was calling .innerhtml from
$array=[]
$(document).ready(function(){
$("#button0").click(function(){
$.get("url/here",$("#form0").serialize(), function(response){
$.each(JSON.parse(response), function(index){
$array.push(JSON.parse(response)[index])
});
$("#div0").html($array[0]);
$("#div1").text($array[2]);
document.getElementById("#div2").innerHTML = $array[4];
});
});
});
.html and .text work nicely so thank you all for answering quickly. .innerHTML does not work and I am curious as to why this is?
Similar questions: HTML/Javascript change div content