Skip to content

Instantly share code, notes, and snippets.

@levmyshkin
Created November 19, 2021 06:42
Show Gist options
  • Save levmyshkin/a4a6714c19b32e3cec8143d76cad507f to your computer and use it in GitHub Desktop.
Save levmyshkin/a4a6714c19b32e3cec8143d76cad507f to your computer and use it in GitHub Desktop.
Drupal javascript behavior execute code once for element
(function ($, Drupal, once) {
Drupal.behaviors.myModuleBehavior = {
attach: function (context, settings) {
once('myCustomBehavior', 'input.myCustomBehavior', context).forEach(function () {
// Apply the myCustomBehaviour effect to the elements only once.
});
}
};
})(jQuery, Drupal, once);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment