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
There's the unbind function documented here:
http://docs.jquery.com/Events/unbind
Fits your example :)
Use the "one" function:
$("#only_once").one("click", function() {
alert('this only happens once');
});
Taken from the jQuery documentation found here:
$("#unbind").click(function () {
$("#theone").unbind('click', aClick)
.text("Does nothing...");
});
In plain JavaScript:
var myDiv = document.getElementById("myDiv");
myDiv.addEventListener('click', clicked, false);
function clicked()
{
// Process event here...
myDiv.removeEventListener('click', clicked, false);
}
Steve