Reputation: 1809
I am trying to attach a click event handler on a button but it doesn't call the click event on the button. I guess I am using wrong selectors. Can anybody help me out?
The HTML:
<button type="submit" class="btn btn-primary btn-block mb20 submitForm" onclick="RemoveValidation()">Search</button>
And here is the JQuery:
$("#txtZip").keyup(function (event) {
debugger;
if (event.keyCode == 13) {
$(".btn .submitForm").click();
}
});
Upvotes: 1
Views: 235
Reputation: 1887
or else you can use submit function.
<form id="form_id">
......
</form>
$("#txtZip").keyup(function (event) {
debugger;
if (event.keyCode == 13) {
$("#form_id").submit();
}
});
Upvotes: 0
Reputation: 115222
Remove the space between them to select element with both class,.btn .submitForm
will search .submitForm
within .btn
.
$("#txtZip").keyup(function (event) {
debugger;
if (event.keyCode == 13) {
$(".btn.submitForm").click();
// ----^--- remove the space
}
});
Upvotes: 2