call the same jQuery function in multiple buttons
Solution 1:
First solution :
function doClick(e) {
$('#modal').reveal({
animation: 'fade',
animationspeed: 150,
closeonbackgroundclick: true,
dismissmodalclass: 'close'
});
return false;
}
$('#button1').click(doClick);
$('#button2').click(doClick);
Second solution :
Give a class "someClass" to all the involved buttons
<input type=button class=someClass ...
and do
$('.someClass').click(function(e) {
...
});
Third solution :
Use the comma to separate ids :
$('#button1, #button2').click(function(e) {
...
});
Generally, the best solution is the second one : it allows you to add buttons in your code without modifying the javascript part. If you add some of those buttons dynamically, you may even do
$(document).on('click', '.someClass', function(e) {
...
});
Solution 2:
Use different ids for buttons and change your function as below.
$('#button1, #button2, #button3').click(function(e) {
.....