title: FontAwesome 5 on click event?
body: <p><strong>What I'm trying to do</strong></p>
  
  <p>I just switched over from Font Awesome 4.7 to Font Awesome 5 and everything is working great except one thing: In part of my site, I use a font awesome icon as a toggle-esk button. On click, I want to change the "open" heart to a "closed" heart icon (fas fa-heart &lt;-> far fa-heart). I can do this by changing the data-prefix in the SVG element in the browser's inspector.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>My problem comes to binding the click listener as the element that was there is removed and replaced with an SVG. I dynamically add elements onto the page that have these heart icons and after generating the HTML with JS handlebars, I use jquerys .on("click") method to get when the button is clicked and toggle the classes. This was fine when the element didn't get replaced, but with the change to SVG's whats the new way of doing this?</p>
  
  <p><strong>Possible Solutions</strong></p>
  
  <p>I read through Font Awesome's "How To" guide and they don't cover topics like this yet. This is a common thing people will want to do so it would be nice to get a list of solutions people can use. Below are two ideas I've thought of but and one that FontAwesome would have to provide but I'm curious if there's a better way:</p>
  
  <ol>
  <li>Use a short timeout before adding listener - seems hacky at best however.</li>
  <li>Use a wrapper element's on click and then search for the SVG element on every click.</li>
  <li>FontAwesome could provide a callback for when an icon has been replaced.</li>
  </ol>
  
  <p><strong>Example Fiddle</strong></p>
  
  <p>Here is a simplified example where a button is dynamically appended to the document (this works fine if using $(document).ready() but I am doing an API request and then generating html dynamically). Clicking the button does not call the listener as the element hasn't finished replacing the element to an SVG.</p>
  
  <p><a href="https://jsfiddle.net/L748ownw/" rel="noreferrer">https://jsfiddle.net/L748ownw/</a></p>
  
  <pre><code>&lt;div id='container'&gt;&lt;/div&gt;
  
  $("#container").append("&lt;i id='heart' class='far fa-heart'&gt;&lt;/i&gt;");
  $(".far").on("click", function() {
    console.log("clicked");
  });
  </code></pre>
  
  <p>This example works fine with FontAwesome 4.7 as the element isn't being replaced.</p>