Binding same function to different elements in jquery
<p>The following code won't work if i replace id with variable. I tried different combination but didn't work. I am using on form elements. Please let me know if anyone knows how to get this work. Thanks.</p>

<p>This works:</p>

<pre><code>$('#Button1, #Button2').click(function() {
// 
});
</code></pre>

<p>Here is my sample code that doesn't work:</p>

<pre><code>&lt;!doctype html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;style&gt;
&lt;/style&gt;
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;                    &lt;script&gt;    
    $(document).ready(function(){
   var Btn1 = $("#buy");
       var Btn2 = $("#preview");        
   $(Btn1, Btn2).click(function(){ console.log("hey");})        
});

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;form&gt;
      &lt;input type="button" value="Preview" id="preview" /&gt;
      &lt;input type="button" value="Buy" id="buy" /&gt;
  &lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
