Bind handler only once for all elements of a class

Louis

How to bind a click event to a class .myclass, so that the handler is executed only once for all .myclass elements, and not executed again if the user clicks on another .myclass element.

$('.myclass').one('click', function() {...});

will execute the handler once per .myclass element, but I need the handler to be executed once, for all .myclass elements.

Thanks

adeneo

Remove the event handler on first click

$('.myclass').on('click.custom', function () {
    $('.myclass').off('click.custom');

    // do stuff

});

using namespaced events makes sure you remove that handler only, and not other click handlers.

FIDDLE

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to trigger toggle() only once on all elements?

How to bind data for shared fragment only once for all controllers and pages?

Apply class only to the elements with the class and not all children

Bind click handler to dynamically created anchor tags fires erroneously and only once

JQuery bind() only tiggered once

Android Handler.postDelayed only working once

Trigger a draw only once for any event handler

Angular: Global Error Handler working only once

python logging ensure a handler is added only once

Change event handler firing only once, jQuery

Run an Ansible handler only once for the entire playbook

error handler works only once in vba

How to attach an event handler only once continuously

jquery event handler only running once

remove only hidden class elements instead of all of them

Using querySelectorAll to get ALL elements with that class name, not only the first

Aurelia - bind only once showing the title in repeater

Python: Tkinter bind("<<Modified>>") works only once

Spark Scala : how to display same rows of dataframe, that differ in one column, only once with all different elements

Query all years, but only once

bind ALL forms at once to jQuery Form possible?

Pytest "run-around-tests" fixture to run only once before all tests in a class

How can I apply function to all new elements with the same class, but only for the newly created elements? (JS function)

How to define event handler as elements class method?

Nested loop only access X elements at once

Return elements that appear only once in array

Select elements as expected, but only once, why?

Print elements of an array that appear only once (C)

How to filter elements in a list that occur only once