Huma Ali
Huma Ali

Reputation: 1809

jquery multiple class selector

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

Answers (2)

Ramesh
Ramesh

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

Pranav C Balan
Pranav C Balan

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

Related Questions