when onclick event click listener fires code example

Example 1: js eventlistener to add and remove stylings

const form = document.querySelector('form');
const fname = document.getElementById('fname');
const lname = document.getElementById('lname');
const para = document.querySelector('p');

form.onsubmit = function(e) {
  if (fname.value === '' || lname.value === '') {
    e.preventDefault();
    para.textContent = 'You need to fill in both names!';
  }
}

Example 2: does click event work only for buttons

button > * {
  pointer-events: none;
}