Reputation: 19826
I have JavaScript method which acts when a particular class (mcb) of forms are submitted:
function BindCloseMessage() {
$(".mcb").submit(function(event) {
alert("closing..."); //Here I want to get the id of form
event.preventDefault();
});
}
In place of alert call, I need to access the id of form whose submit is called. How can I do it? Even better will be the tip for accessing any attribute...
Thanks
Upvotes: 3
Views: 5762
Reputation: 78667
the id of the form being submitted will be
this.id
or in jQuery
$(this).attr('id') //although why type the extra letters?
Upvotes: 7
Reputation: 268344
$(".mcb").submit(function(e){
e.preventDefault();
$(this).attr("id"); // Returns FORM ID
});
You can learn more about jQuery's attribute-methods at http://docs.jquery.com/Attributes
Upvotes: 4