event handler code example

Example 1: most used events in javascript

most used events in javascript

Example 2: error handler

function handlerError(request, response){
    response.status(500).send('opps');
}

.catch(handlerError);

Example 3: events in javascript

//this is an event detector for a mouseclick with Jquery
$('#id').on('click',function(){
    yourFunction(args);
});

Example 4: 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!';
  }
}

Tags:

Php Example