Is it Possible to add an event Listener to a button outside a form?

I'm trying to create a calculator app. But the event Listener associated with the buttons won't work except it's gotten with an "Id" The buttons is located in a div with a class name of delButtons and when I tried using

const nButtons = document.querySelectorAll('.delButtons buttons');

Chrome dev shows that nButtons contains all the buttons but yet event Listeners assigned to them are not active.

This method works when used with the input elements of type buttons and event Listener associated with are active. Why is the case different with buttons

Ps: the buttons are not nested in a form so they have no type.

To answer your primary question, yes, you can add an event handler to a button that is not in a form.

To be able to help you any further we would need a link to your code.

1 Like