Jquery/quicktime events

I was hoping to make a little quicktime event by checking the last 4 keystrokes pressed and adding them to an array to be checked in the next passage. It works, but once on the testing passage it’s still trying to run the jquery code from the previous page. How would I limit the jquery script to just the current passage. Thanks!

<<set $keystroke = []>>\

<span id = "testclicks"></span>

<<done>>\
<<script>>
	$(document).on("keydown", function (event) {
	$.wiki("<<set $keystroke.push(event.which)>><<replace #testclicks>>$keystroke<</replace>><<if $keystroke.length >= 4>><<goto 'qte results'>><</if>>");
});
<</script>>
<</done>>\

Twine Version: 2.61

Use the <jQuery>.one() method instead of <jQuery>.on().

The .on() method attaches a permanent handler, which you’d have to remove. The .one() method instead attaches a single-use handler.