.change() in pure js 1

.change() in pure js

/* event listener */
document.getElementsByName("Thing")[0].addEventListener('change', doThing);

/* function */
function doThing(){
   alert('Horray! Someone wrote "' + this.value + '"!');
}

Here is what the above code is Doing:
1. We’re selecting the input element with the name “Thing” and adding an event listener to it.
2. When the event listener is triggered, we’re alerting the value of the input element.

Now, let’s add some more code to the function:

Similar Posts