My HTML code:
<div class="container">
<div class="question-card">
<h1 id="question1">This is the question</h1>
</div>
<div class="answer-choices">
<div class="row1">
<span class="choice1" id="one" onclick="choice1()">One</span>
<span class="choice2" onclick="choice2()">Two</span>
</div>
<div class="row2">
<span class="choice3" onclick="choice3()">Three</span>
<span class="choice4" onclick="choice4()">Four</span>
</div>
</div>
<button id="btn" onclick="next()">Next</button>
My js code:
function clickNextText(){
document.getElementById("question1").innerHTML="Answer recorded, Click next to proceed"
} //This is working fine
var str
element = document.getElementById('btn');
if (element != null) {
str = element.value;
}
else {
str = null;
}
console.log(str) //This is however returning null.
I don't understand what is wrong here. Moreover every element with an id after the div with class answer-choices isn't detected. While the script code when placed in .html itself works fine.