Matt B Matt B - 5 months ago 17
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