Personally, I would like to handle the DOM:
$(function() {
$("button").each(function() {
var matches = $(this).attr("id").match(/^user_(\d+)_edit$/);
if (matches) {
$(this).data("user_edit_id",matches[1]);
}
}
});
Then you can simply:
$("button").filter(function(){
return $(this).data("user_edit_id");
}).click(function(){
var user_id = $(this).data("user_edit_id");
alert('click on user edit button with ID ' + user_id);
});
This is not an ideal solution for what you want, but it is one way ...
source
share