(function ($, Drupal) { Drupal.behaviors.robib_solr_alterlBehavior = { attach: function (context, settings) { // Attach event to the modal link without using once() $('#open-modal-link', context).click(function (e) { e.preventDefault(); // Create the modal content var modalContent = ''; // Append the modal to the body $('body').append(modalContent); // Show the modal $('#help-modal').fadeIn(); // Close the modal when clicking the close button $('#help-modal .close-button').click(function () { $('#help-modal').fadeOut(function () { $('#help-modal').remove(); // Remove modal from DOM after closing }); }); // Close the modal when clicking outside the modal content $(window).click(function(event) { if ($(event.target).is('#help-modal')) { $('#help-modal').fadeOut(function () { $('#help-modal').remove(); // Remove modal from DOM }); } }); }); } }; })(jQuery, Drupal);