Quote:
Originally Posted by Sdumau1
is it possible, give an id to each answer, where one ID for all wrong answers and another id to all "Correct" and use a switch to never appear the image wrong twice?
|
No, all ids in an HTML file need to be unique, however, you could mark right and wrong answers with different class names.
Code:
<p><img alt="" class="wrong" onclick="checkAnswer(this)" src="../Images/help.png"/>Answer 3</p>
<p><img alt="" class="correct" onclick="checkAnswer(this)" src="../Images/help.png"/>Answer 4</p>
You could then have an onclick function check the class name and display the desired image. For example:
Code:
function checkAnswer(img) {
if (img.classList.contains("correct")) {
img.src = "../Images/ok-filled.png";
} else {
img.src = "../Images/cancel-filled.png";
}
}
I've attached an updated test file that demonstrates this method.
Before you continue, you really should work through a JavaScript tutorial for beginners, for example, the
JavaScript Tutorial by w3schools.
Also don't forget to periodically check your epub with the
IDPF EPUB validator.