title: Jquery click event not registering if the user clicks another link
body: <p>This has been bugging me as I'm not really sure what is going on but it feels like a beginner problem. Basically I have a button that displays a chat box if clicked, and another button that just acts as a link to a further section of the page.</p>
  
  <ul>
  <li>If I click the chat button first, my Jquery code is called and it displays correctly</li>
  <li>If I click the anchor link button first, I am indeed going to the right section; but clicking the chat button afterwards does not call the Jquery code anymore (click event not registered)</li>
  </ul>
  
  <p>HTML code:</p>
  
  <pre><code>&lt;a href="#what-you-get" class="btn btn-white btn-border radius-lger min-width"&gt;&lt;strong&gt;Learn More&lt;/strong&gt;&lt;/a&gt;
  &lt;a href="#" data-role="toggle-chatbot" data-display="1" class="btn btn-white radius-lger min-width"&gt;&lt;strong&gt;Join Our Waitlist&lt;/strong&gt;&lt;/a&gt;
  </code></pre>
  
  <p>JS code:</p>
  
  <pre><code>$(function () {
  
    // Shows or hides the chatbot
    $('[data-role="toggle-chatbot"]').on('click', function(e) {
      e.preventDefault();
      if($(this).attr('data-display') == '1') {
        $('.container-chat').removeClass('hide');
      }
      else {
        $('.container-chat').addClass('hide');
      }
    });
  
  });
  </code></pre>
  
  <p>Any suggestion? Thanks in advance!</p>
  
  <p>EDIT: Solved thanks to <a href="https://stackoverflow.com/questions/17600093/rails-javascript-not-loading-after-clicking-through-link-to-helper">this</a>. The problem was due to Turbolinks in Ruby on Rails 5 and the following code fixed things (the change to .toggle-chatbot was to optimise things based on Rajesh's comment):</p>
  
  <pre><code>$(document).on('turbolinks:load', function () {
    // Shows or hides the chatbot
    $('.toggle-chatbot').on('click', function(e) {
      e.preventDefault();
      if($(this).attr('data-display') == '1') {
        $('.container-chat').removeClass('hide');
      }
      else {
        $('.container-chat').addClass('hide');
      }
    });
  
  });
  </code></pre>