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.
This works:
$('#Button1, #Button2').click(function() {
//
});
Here is my sample code that doesn't work:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Untitled Document</title>
<style>
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script>
$(document).ready(function(){
var Btn1 = $("#buy");
var Btn2 = $("#preview");
$(Btn1, Btn2).click(function(){ console.log("hey");})
});
</script>
</head>
<body>
<form>
<input type="button" value="Preview" id="preview" />
<input type="button" value="Buy" id="buy" />
</form>
</body>
</html>