Here is the code for what I am basically trying to do:
document.body.addEventListener("keypress", f1, false);
function f1(e){
var span = document.createElement("span");
window.setInterval(function(){
...
window.clearInterval(this);
document.body.removeChild(span);
}
So in short, I'm trying to make a new DOM element, and then attach a timer to it that will be able to reference that particular object. The problem is, I don't know how to do the context, so this
just references window
, and JavaScript throws an error when I try to reference span
(which I wasn't expecting to work anyway). How can I set the context of the interval to the DOM element I created in that function?