title: How do I use click logic in my .js.erb file to render different HTML depending on the button which was clicked?
body: <p>I have a four step form that the user goes through to complete a process. Each step is a separate partial. I want to guide the user through the form using Ajax and decide which partial to display based on which step they are on in the process. I can tell which step they are on based on the button that is clicked. But the code below is not rendering anything in the browser once I add in the click logic. Things work fine when I take out the click listener.</p>
  
  <pre><code>$(function(){
      $("#ask2-btn").click(function(e){
          $("div#ask").html("&lt;%= escape_javascript(render('asks/ask3')) %&gt;")
      });
  
      $("#ask3-btn").click(function(e){
          $("div#ask").html("&lt;%= escape_javascript(render('asks/ask4')) %&gt;")
      });
  
  });
  </code></pre>
  
  <p><strong>UPDATE:</strong> Here is the response from the browser which isn't rendering</p>
  
  <pre><code>$(function(){
      $("#ask2-btn").click(function(e){
          $("div#ask").html("&lt;p class=\"lead\"&gt;Help with this issue&lt;\/p&gt;\n&lt;ul&gt;&lt;li class=\"profile\"&gt;Sam Smith&lt;\/li&gt;&lt;\/ul&gt;\n&lt;em&gt;\"Expected outcome of the ASK?&lt;\/em&gt;\n    &lt;form accept-charset=\"UTF-8\" action=\"/asks/125\" class=\"edit_ask\" data-remote=\"true\" id=\"edit_ask_125\" method=\"post\"&gt;&lt;div style=\"margin:0;padding:0;display:inline\"&gt;&lt;input name=\"utf8\" type=\"hidden\" value=\"&amp;#x2713;\" /&gt;&lt;input name=\"_method\" type=\"hidden\" value=\"put\" /&gt;&lt;input name=\"authenticity_token\" type=\"hidden\" value=\"2/vhLplWpnB5fSrkjgku27jzaJ0lwLK3GeOWchn6r8M=\" /&gt;&lt;\/div&gt;\n        \n        &lt;input id=\"ask_category\" name=\"ask[category]\" type=\"hidden\" value=\"Advice\" /&gt;\n        &lt;input class=\"btn btn-success btn-category\" name=\"commit\" type=\"submit\" value=\"Advice\" /&gt;\n&lt;\/form&gt;    &lt;form accept-charset=\"UTF-8\" action=\"/asks/125\" class=\"edit_ask\" data-remote=\"true\" id=\"edit_ask_125\" method=\"post\"&gt;&lt;div style=\"margin:0;padding:0;display:inline\"&gt;&lt;input name=\"utf8\" type=\"hidden\" value=\"&amp;#x2713;\" /&gt;&lt;input name=\"_method\" type=\"hidden\" value=\"put\" /&gt;&lt;input name=\"authenticity_token\" type=\"hidden\" value=\"2/vhLplWpnB5fSrkjgku27jzaJ0lwLK3GeOWchn6r8M=\" /&gt;&lt;\/div&gt;\n        \n        &lt;input id=\"ask_category\" name=\"ask[category]\" type=\"hidden\" value=\"Introduction\" /&gt;\n        &lt;input class=\"btn btn-success btn-category\" name=\"commit\" type=\"submit\" value=\"Introduction\" /&gt;\n&lt;\/form&gt;    &lt;form accept-charset=\"UTF-8\" action=\"/asks/125\" class=\"edit_ask\" data-remote=\"true\" id=\"edit_ask_125\" method=\"post\"&gt;&lt;div style=\"margin:0;padding:0;display:inline\"&gt;&lt;input name=\"utf8\" type=\"hidden\" value=\"&amp;#x2713;\" /&gt;&lt;input name=\"_method\" type=\"hidden\" value=\"put\" /&gt;&lt;input name=\"authenticity_token\" type=\"hidden\" value=\"2/vhLplWpnB5fSrkjgku27jzaJ0lwLK3GeOWchn6r8M=\" /&gt;&lt;\/div&gt;\n        \n        &lt;input id=\"ask_category\" name=\"ask[category]\" type=\"hidden\" value=\"Support\" /&gt;\n        &lt;input class=\"btn btn-success btn-category\" name=\"commit\" type=\"submit\" value=\"Support\" /&gt;\n&lt;\/form&gt;    &lt;form accept-charset=\"UTF-8\" action=\"/asks/125\" class=\"edit_ask\" data-remote=\"true\" id=\"edit_ask_125\" method=\"post\"&gt;&lt;div style=\"margin:0;padding:0;display:inline\"&gt;&lt;input name=\"utf8\" type=\"hidden\" value=\"&amp;#x2713;\" /&gt;&lt;input name=\"_method\" type=\"hidden\" value=\"put\" /&gt;&lt;input name=\"authenticity_token\" type=\"hidden\" value=\"2/vhLplWpnB5fSrkjgku27jzaJ0lwLK3GeOWchn6r8M=\" /&gt;&lt;\/div&gt;\n        \n        &lt;input id=\"ask_category\" name=\"ask[category]\" type=\"hidden\" value=\"Money\" /&gt;\n        &lt;input class=\"btn btn-success btn-category\" name=\"commit\" type=\"submit\" value=\"Money\" /&gt;\n&lt;\/form&gt;    &lt;form accept-charset=\"UTF-8\" action=\"/asks/125\" class=\"edit_ask\" data-remote=\"true\" id=\"edit_ask_125\" method=\"post\"&gt;&lt;div style=\"margin:0;padding:0;display:inline\"&gt;&lt;input name=\"utf8\" type=\"hidden\" value=\"&amp;#x2713;\" /&gt;&lt;input name=\"_method\" type=\"hidden\" value=\"put\" /&gt;&lt;input name=\"authenticity_token\" type=\"hidden\" value=\"2/vhLplWpnB5fSrkjgku27jzaJ0lwLK3GeOWchn6r8M=\" /&gt;&lt;\/div&gt;\n        \n        &lt;input id=\"ask_category\" name=\"ask[category]\" type=\"hidden\" value=\"Don&amp;#x27;t know\" /&gt;\n        &lt;input class=\"btn btn-success btn-category\" name=\"commit\" type=\"submit\" value=\"Don&amp;#x27;t know\" /&gt;\n&lt;\/form&gt;")
      });
  
      $("#ask3-btn").click(function(e){
          $("div#ask").html("&lt;p class=\"lead\"&gt;Help with this issue&lt;\/p&gt;\n&lt;ul&gt;\n  &lt;li class=\"profile\"&gt;Sam Smith&lt;\/li&gt;\n &lt;li class=\"check\"&gt;&lt;\/li&gt;\n&lt;\/ul&gt;\n &lt;hr/&gt;\n &lt;a href=\"/\"&gt;Add another ASK&lt;\/a&gt;")
      });
  
  });
  </code></pre>