How do you attach a event to element which should be executed only once?

Technology CommunityCategory: jQueryHow do you attach a event to element which should be executed only once?
VietMX Staff asked 3 years ago

Using jQuery one() method. This attaches a handler to an event for the element. The handler is executed at most once per element. In simple terms, the attached function will be called only once.

$(document).ready(function() {
    $("#btnDummy").one("click", function() {
        alert("This will be displayed only once.");
    });
});