Somehow in js in const questionEl = document.getElementById('question');
is returning null. I checked all the id selectors and found out that they were all returning null. I cannot understand the cause of the problem. I have elements with the specified id. Then why is still returning null?
const questionEl = document.getElementById('question');
const a_text = document.getElementById("a");
console.log("This is >>", a_text);
const b_text = document.getElementById("b");
const c_text = document.getElementById("c");
const d_text = document.getElementById("d");
let currentQuestion = 0;
function loadQuiz() {
console.log(quizData[currentQuestion].question)
questionEl.innerHTML = quizData[currentQuestion].question;
currentQuestion++;
}
loadQuiz();
<div class="quiz-container">
<div class="quiz-header">
<h2 id="question">Question text</h2>
</div>
<ul class="quiz-options">
<li>
<input type="radio" id="a" name="answer">
<label for="a" id="a_text">Question</label>
</li>
<li>
<input type="radio" id="b" name="answer">
<label for="a" id="b_text">Question</label>
</li>
<li>
<input type="radio" id="c" name="answer">
<label for="a" id="c_text">Question</label>
</li>
<li>
<input type="radio" id="d" name="answer">
<label for="a" id="d_text">Question</label>
</li>
</ul>
<button>Next</button>
</div>