Reputation: 21206
How can I get the form object containg the button which I clicked? I do not want to give the form an id.
$('#buttonid@(Model.Id)').on('click', function (e) {
e.preventDefault();
// get form here which is around the link button I clicked?
}
Upvotes: 1
Views: 25
Reputation: 337580
You can use closest()
to find a parent element matching a given selector:
$('#buttonid@(Model.Id)').on('click', function (e) {
e.preventDefault();
var $form = $(this).closest('form');
// do something with $form...
});
Upvotes: 4