Greetings everyone, I've been attempting to integrate both click and keypress functionalities into my function, but unfortunately, nothing I've attempted so far has yielded any success. Here's the code snippet:
function victoryMessage() {
$(document).off("keyup", handleKeyUp);
$('#feedback').append("Bravo!<br><br><div id='replay' class='button'>Nastavi</div>");
$('#replay').on("click",function () {
if(questionBank.length>3) {
gameScreen();
}
else {
finalPage();
}
});
$(document).off("tap", keepFocus).trigger("tap");
}
After multiple trials, I have tested the following approaches:
$("#replay").on("click keyup", function (e) {
if (e.type == "click" || e.keyCode == 13) {
if(questionBank.length>0) {
gameScreen();
}
else {
finalPage();
}
}
});
as well as
var callback = function() {
if(questionBank.length>0) {
gameScreen();
}
else {
finalPage();
}
};
$("#replay").keypress(function() {
if (event.which == 13) callback();
});
$('#replay').click(callback);
In addition, I tried another approach:
$(document).on("keypress", function(e){
if (e.which == 13) {
testKey();
}
});
I experimented with various methods, yet none of them produced the desired outcome. To view the complete code in action, please visit
EDIT: To clarify based on Andy's suggestion, I aim for the click action to be triggered only when the replay button is clicked, while the enter key should activate it anywhere within the document.