jQuery once callback function is not called I'm struggling with the once function. The once callback function is not called. I'm trying to use like this:

(function ($, Drupal){
  Drupal.behaviors.my_module = {
    attach: function (context, settings) {
      console.log('this runs');

      $('.my_selector', document).once('special-mark', function() {
        console.log('this never called');
      });

      console.log('this also called');
    }
  }
})(jQuery, Drupal);


In the library file I use the following:

dependencies:
  - core/jquery
  - core/jquery.once
  - core/drupal


There's no a single error in the console. It's just simply not called the callback... How can I make it work?

Drupal: 8.8.4
jQuery: 3.4.1
jQuery once doesn't take a callback as a second parameter. You need to loop over the returned list of elements and apply a callback using one of the standard methods like each:

$('.my_selector', document).once('special-mark').each(function() {
  console.log('this will be called');
});