Reputation: 1107
I have several buttons with type button:
<button type="button" class="btn btn-default">Plain old button.</button>
and some important buttons with type submit:
<button type="submit" class="btn btn-default">Submit button!</button>
I want to listen to click events on buttons with type submit, but not the others.
Upvotes: 0
Views: 449
Reputation: 1107
This can be done using CSS selectors:
$(function() {
$('button[type=submit]').click(function () {
alert('Submit button clicked.');
});
});
W3C provides a CSS Selector Reference. All of which are supported by jQuery. The complete set jQuery selectors can be found at jQuery API. Here is a complete example at jsfiddle.
Upvotes: 2
Reputation: 40639
Try this,
$(function() {
$('button').click(function (e) {
if($(this).attr('type') =='submit') {
alert($(this).attr('type'));
}
});
});
Upvotes: 0