0

Uncaught TypeError: Cannot set property 'innerHTML' of null

var questions = [ 'hi', 'fyn', 'Thank u' ]; var num == 0; var output = document.querySelector("#Student"); output.innerHTML = questions[0]; var inputBox = document.querySelector("#ans"); function showResponse(){ var input = inputBox.value; if(inputBox.value == "") { } else { if(num == 0) { output.innerHTML = '${ans} hi'; inputBox.value = ""; ++num; setTimeout(changeQuestion, 2000); } else if(num == 1) { output.innerHTML = '${ans} fyn'; inputBox.value = ""; ++num; setTimeout(changeQuestion, 2000); } } } function changeQuestion(){ output.innerHTML = questions[num]; if(num == 2) { inputBox.style.display = "none"; } } $(document).on('keypress', function(e) { if(e.which == 13){ showResponse(); } })

21st Apr 2018, 7:56 AM
ammu
1 Antwort
+ 18
Wrap your whole code in: onload = function() { //code }; //page must have loaded first to start grabbing elements from it...
21st Apr 2018, 8:00 AM
Valen.H. ~
Valen.H. ~ - avatar