Matt B Matt B - 1 month ago 4x
HTML Question

Jquery .click function not working for button

I have the code

$('#resetbtnB').click(function() {

This will work if 'resetbtnB' is for example a paragraph or an image. However it does not work when 'resetbtnB' is an input button.


Works with

<p id="resetbtnB"> Reset </p>

Not with

<input type="submit" value="Reset" name="resetbtnB" id="resetbtnB"/>

Why does this code not work for an input button and how can I change it to work?


Because type="submit" also triggers submit event when it is inside form so it is overriding click event. So either try to remove type "submit" and put "button" write like this

<input type="button" value="something" name="resetbtnB" id="resetbtnB"/>

Or write jquery function .submit

Docs :

Demo :,js,output