title: How do I set a jQuery selector in coffeescript using a variable?
body: <p>Im writing a Rails app, and I have multiple forms on the same page that all have different ids. in coffee script, I'm trying to set the identifier to access the text area in each. heres a quick example of what the html looks like in the browser.</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;a href="#" class="link" data-plan="1"&gt;Click here&lt;/a&gt;
  &lt;form id="new_item_plan_1"&gt;
    &lt;textarea id="plan_1_item_field"&gt;&lt;/textarea&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Setting the plan id and trying to access the text area</p>
  
  <pre><code>plan_id = 0
  $(".link").click -&gt;
    plan_id = $(this).data("plan")
  $("#plan_"+plan_id+"_item_field").keypress -&gt;
    ...Some code...
  </code></pre>
  
  <p>So I have the <code>plan_id</code> variable initialized first, then set it to the <code>.link</code>s data-plan value. But my key press event doesn't work on the textarea and I dont get an error in the console.</p>
  
  <p>When I make a test link and <code>console.log</code> it...</p>
  
  <pre><code>plan_id = 0
  $(".link").click -&gt;
    plan_id = $(this).data("plan")
  $("#test).click -&gt;
    console.log(plan_id)
  </code></pre>
  
  <p>it prints the correct <code>plan_id</code> value in the console just fine, so I have to be doing something wrong in the textarea identifier. What am I going wrong? Thanks.     </p>
  
  <p>Link to jsfiddle, notice how the keypress event doesn't work <a href="https://jsfiddle.net/cfscr/175/" rel="nofollow">https://jsfiddle.net/cfscr/175/</a></p>