Reputation: 29557
How do I disable this event listener so that it only fires once?
document.getElementById('element').ontouchmove = function (e)
{
DISABLE HERE
do something that should only happen once
};
Upvotes: 0
Views: 1509
Reputation: 27002
document.getElementById('element').ontouchmove = function (e) {
this.ontouchmove = null;
// Do something here.
};
Upvotes: 2
Reputation: 3800
Set a Boolean to false after first execution, which will be checked each time before the function runs:
var doTouchEvent = true;
document.getElementById('element').ontouchmove = function (e)
{
if(doTouchEvent){
DISABLE HERE
do something that should only happen once
doTouchEvent = false;
}
};
Upvotes: 0