Reputation:
I have a click
event I wired up on a div
on my page.
Once the click
event has fired, I want to unbind the event on that div
.
How can I do this? Can I unbind it in the click
event handler itself?
Upvotes: 0
Views: 457
Reputation: 125480
In plain JavaScript:
var myDiv = document.getElementById("myDiv");
myDiv.addEventListener('click', clicked, false);
function clicked()
{
// Process event here...
myDiv.removeEventListener('click', clicked, false);
}
Steve
Upvotes: 2
Reputation: 707
There's the unbind function documented here:
http://docs.jquery.com/Events/unbind
Fits your example :)
Upvotes: 0