1

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();
    }
});

2 Answers 2

2

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
    }
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for telling me the difference! :)
@HumaAli : glad to help
0

or else you can use submit function.

<form id="form_id">
......
</form>

$("#txtZip").keyup(function (event) {
    debugger;
    if (event.keyCode == 13) {
        $("#form_id").submit();
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.