Nov 21, 2019 in Drupal 8, Snippets

A thing developers can forget while testing, is to make sure all functionality of your module is stable when used in the context of ajax. Some plugins might stop working after an ajax call on the page. This is how to prevent such thing.

This is the correct implementation of your javascript file: 

( function ($) {
    Drupal.behaviors.mymodule = {
        attach: function(context,settings) {

            //code goes here