Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery call same function when two different buttons are clicked

I have a button with class try and when its clicked there is a function that is being called, now I want to create a button called start that will do the same, and I don't want to copy paste whole code in that button click handler, is there a way to say lets say if try or start do the following in jquery?

like image 457
Grigor Avatar asked Jul 09 '26 15:07

Grigor


1 Answers

I assume that since you said a button called start that start is the id. That is why I am using a # instead of a . to reference it.

$('.try, #start').click(function(e){
    YourFunction();
});

if start is the class, then use this. # indicates an id, while . indicates a class.

$('.try, .start').click(function(e){
    YourFunction();
});
like image 139
Dutchie432 Avatar answered Jul 13 '26 01:07

Dutchie432