I have two chained mouse-events:
$('body > form').on("mousedown", function(e){
//Do stuff
}).on("mouseup", function(){
/*More stuff, including
window.addEventListener(...
*/
});
However, when I try to off()
them both from another external function, I can only off()
mousedown
, but not mouseup
, whose functionality continues to work.
Could that nested addEventListener
be preventing me from offing its event? (
By the way, it doesn't matter how I
chain: ($().off().off();
), or unchain ($().off(); $().off();
), or combine ($().off(A B);
) or reverse (A B <-> B A) the elements; consistently, off(mousedown)
works, but never off(up)
.
Here's my full JS code:
(The problematic part is the 2nd script, at the end:)
<script>
function comment() {
$('body > form').on("mousedown.markerPlacer", function(e){
//Place the cursor marker on the screen
var newComment2 = $('<div id="newComm" class="marker" class="deg45" ↑</div>');
$('form').append(newComment2);
}).on("mouseup", function(){
//Now use the Q-key to rotate the marker.
window.addEventListener("keydown", extraKey, false);
window.addEventListener("keyup", keysReleased2, false);
function extraKey(e) {
var deg = e.keyCode;
if (deg == 81) { //81 is the keycode, which codes for Q
$('#newComm').attr('class', 'marker').addClass('deg0');
} else {
return false;
};
e.preventDefault();
};
function keysReleased2(e) {
e.keyCode = false;
};
});
};
</script>
<script>
function dismissComment() {
$('body > form').off("mousedown mouseup");
}
</script>