title: Action fires more than once on second load
body: <h2>PROBLEM</h2>
  <p>I have a modal that I use app wide. This modal's content and confirm action changes depending on what is clicked.</p>
  <p>The first time this modal launches, everything is fine and dandy, and the modal's confirm only fires once.</p>
  <p>Any other time, the modal fires the confirm action 3 times.</p>
  <h2>MY CODE</h2>
  <p>The modal and button in my HTML page:</p>
  <pre><code>&lt;div class=&quot;modal fade&quot; tabindex=&quot;-1&quot; role=&quot;dialog&quot; id=&quot;confirmationModal&quot;&gt;
      &lt;div class=&quot;modal-dialog modal-sm&quot;&gt;
          &lt;div class=&quot;modal-content&quot;&gt;
              &lt;div class=&quot;modal-header&quot;&gt;&lt;/div&gt;
              &lt;div class=&quot;modal-body&quot;&gt;&lt;/div&gt;
              &lt;div class=&quot;modal-footer&quot;&gt;
                  &lt;button class=&quot;btn btn-danger&quot; data-event=&quot;click&quot; data-action=&quot;closeModal&quot;&gt;Cancel&lt;/button&gt;
                  &lt;button class=&quot;btn btn-success&quot; data-event=&quot;click&quot;&gt;Confirm&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;i class=&quot;fa fa-trash linked-fa red-fa&quot; data-confirm=&quot;temDelete&quot; data-event=&quot;click&quot; data-id=&quot;template&quot; data-header=&quot;Confirm Delete&quot; data-body=&quot;Are you sure you want to delete Template?&quot; data-action=&quot;showModal&quot;&gt;&lt;/i&gt;
  </code></pre>
  <p>And my Javascript (well actually, JQuery)</p>
  <pre><code>$(document).ready(function(e) {
      setEventListeners();
  });
  
  function setEventListeners() {
      // Find all elements with a data-action attribute
      $('[data-action]').each(function() {
  
          // Set the callback to the action
          // Link the event to the callback
          var theCallback = $(this).data('action');
          var theEvent = $(this).data('event');
  
          // If theEvent == 'load', do it immediately
          if(theEvent == 'load') {
              executeFunctionByName(theCallback,this,$(this));
          } else {
              // When the event fires, do the callback
              $(this).on(theEvent,function(e) {
                  executeFunctionByName(theCallback,window,$(this),e)
              });
          }
      });
  }
  
  function executeFunctionByName(functionName,context) {
      // I actually have no freakin idea what this does
  
      // Google made me copy paste it.
      var args = [].slice.call(arguments).splice(2);
      var namespaces = functionName.split(&quot;.&quot;);
      var func = namespaces.pop();
  
      for(var i = 0; i &lt; namespaces.length; i++) {
          context = context[namespaces[i]];
      }
  
      if(typeof context[func] !== 'undefined') {
          return context[func].apply(this, args);
      } else {
          console.log('Function not found.');
      }
  }
  
  function showModal(element) {
  
      // Get and set the body and header of the modal
      $('#confirmationModal .modal-header').html(element.data('header'));
      $('#confirmationModal .modal-body').html(element.data('body'));
  
      // Transfer all data fields from the clicked element to the confirm button in the Modal
      $.each(element.data(),function(i,v) {
          if(i != 'event') {
              if(i == 'confirm') { i = 'action'; } // If the data is confirm, change it to action, as this is the modal's action
              $('#confirmationModal .modal-footer .btn-success').attr('data-' + i,v);
          }
      });
  
      setEventListeners();
      // Set the page listeners and show the modal
      $('#confirmationModal').modal('show');
  }
  
  function closeModal() {
      $('#confirmationModal').modal('hide');
  }
  
  function temDelete() {
      $('.actionsfired').append('Delete Fired&lt;br&gt;');
      closeModal();
  }
  </code></pre>
  <p>I've created a <a href="https://jsfiddle.net/Low6d2da/2/" rel="nofollow noreferrer">fiddle that replicates this behaviour</a>.</p>
  <h2>QUESTION</h2>
  <p>How can I prevent the confirm action from being fired 3 times?</p>