Multiple handlers for one event in JavaScript
Multiple functions can be attached to one element at once. Let's look at an example. Let's have a button:
html<input id="button" type="submit">
Let's say we have two functions:
javascriptfunction func1() {
console.log('1');
}
function func2() {
console.log('2');
}
Get a link to our button into a variable:
javascriptlet button = document.querySelector('#button');
And now let's bind both the first and second functions to our button as click handlers:
javascriptbutton.addEventListener('click', func1);
button.addEventListener('click', func2);
Задание 1
Given a paragraph:
html<p id="elem">text</p>
Given the following functions:
javascriptfunction func1() {
console.log('1');
}
function func2() {
console.log('2');
}
function func3() {
console.log('3');
}
Bind all these functions to our paragraph.