[quote=āiridion9, post:14, topic:230718, full:trueā]
This is what I wanted below to incorporate into your prototype codes.[/quote]
Okay, Iāll do this step by step on the jsfiddle example.
<div id="right-answer"></div>
[quote=āiridion9, post:14, topic:230718, full:trueā]
Now let say the var ans=ātestingā , how to fetch the value of variable ans[/quote]
That all entirely depends on the scope within which the ans variable is residing. You can only use the ans variable when you in the scope of that ans variable, or in a deeper scope than where it is.
Further details on your particular situation in regard to the ans variable will be required before a satisfactory answer can be given.
In the meantime though, I will assume that the ans variable is local to the other code that is being run here.
var ans = "testing";
We can update the event handler to do that. Previously it was just calling the showAnswer function, but now we can use a handler function that will help to coordinate things.
function answerHandler() {
showAnswer(answers);
replaceContent(rightAnswer, ans);
}
And that can be done with the use of a replaceContent function:
function replaceContent(selector, content) {
getEl(selector).innerHTML = content;
}
An updated example can be seen at https://jsfiddle.net/pmw57/tm4t40qu/4/