Fortunately, it’s relatively easy to create one-time event handlers in JavaScript. The process: A handler is assigned to an event, such as clicking an element. When the element is clicked, the handler runs. The handler is removed. Further clicks on that element will no longer call the function. jQuery Let’s look at the simplest solution first. If you’re using jQuery, there’s a little-known one() $("#myelement").one( "click", function() { alert("You'll only see this once!"); } ); It’s used identically to other jQuery event methods. For more information, refer to api.jquery.com/one/ .
Read full article from How to Create One-Time Events in JavaScript
No comments:
Post a Comment