Context
I have 3 buttons on several lines (edit, delete, unsuscribe).
This 3 buttons are 3 different classes but the same click handler.
This classes are equals to the names of 3 actions using for an ajax call.
So into the click handler, I need to retrieve the specific part of the selector which has been clicked.
Currently I use the following code that I wrote
Question
In 2-3 lines and using class=action system, is there a better way to solve my issue?
I’m looking for something like that but I didn’t find:
$.post(url + '&action=' + classClickedIntoTheSelector.replace(/\./g, '') ...
Code + JSFiddle
<button class="actionLink edit btn">Éditer</button>
<button class="actionLink delete btn btn-warning">Supprimer</button>
$('.edit, .delete').click(function () {
var a = $('.this, .that').selector.replace(/\./g, '').split(', ');
var b = $(this).attr('class').split(' ');
var action;
for (var i = 0; i < a.length; i++) {
for (var j = 0; j < b.length; j++) {
action = a[i] == b[j] ? a[i] : action;
}
}
$.post(url + '&action=' + action...
});
Finally I used the generic class and a data-attribute: