Single click function in a Drupal behaviour? The following in a Drupal behaviour is working fine:

  $('.trigger', context).click(function(e){
    e.preventDefault();
    $('.target').toggleClass('open');
  });


However I know that I should be using the once function. Is the following correct? It does work but so did the code above so im not sure how to check if its been done with best practices.  

  $('.trigger', context).once('toggle-name', function(){
    $(this).click(function(e) {
      e.preventDefault();
      $('.target').toggleClass('open');
    });
  });
If you don't use .once() then your code will still work but - depending on whatever else happens on the page - your click() function may be attached multiple times to the same element, which is less efficient and may cause undesired effects if, as in this case, you are using a toggle function in your callback.

Because you are limiting the scope of your selector by context, multiple attachment is less likely, but you should definitely use once() if you want your code to be robust.