Edit: JSFiddle (warning: I don't think preventDefault()
works in the jsfiddle window, so it will probably redirect you, I didn't test with other browsers.) and another example with source. The second example has a similar code structure, but it's obviously a quick and dirty example; I want to know if there is a better way to do it. It mostly being event binding and maintaining a "const
" between various unassociated event function calls.