NodeList.on

NodeList.on(evtNames,fn)

evtNamesOne or more space-separated event types

fnA function to execute when the event is triggered

Attach an event handler function for one or more events to each element in NodeList

<button class="cl">Ok</button> <button class="cl">Retry</button> <button class="cl">Cancel</button> <script> var btns = document.querySelectorAll(".cl"); btns.on("click", function() { alert("clicked"); }) </script>

NodeList.off

window.off(evtNames,fn)

evtNamesOne or more space-separated event types

fnA handler function previously attached for the event(s)

Remove an event handler.

<button class="cl">Ok</button> <button class="cl">Retry</button> <button class="cl">Cancel</button> <script> var btns = document.querySelectorAll(".cl"); var fn = function() { alert("clicked, work only once"); btns.off("click", fn); }; btns.on("click", fn); </script>