⊗jsPmDmSH 346 of 504 menu

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:

<input id="button" type="submit">

Let's say we have two functions:

function func1() { console.log('1'); } function func2() { console.log('2'); }

Get a link to our button into a variable:

let button = document.querySelector('#button');

And now let's bind both the first and second functions to our button as click handlers:

button.addEventListener('click', func1); button.addEventListener('click', func2);

Given a paragraph:

<p id="elem">text</p>

Given the following functions:

function func1() { console.log('1'); } function func2() { console.log('2'); } function func3() { console.log('3'); }

Bind all these functions to our paragraph.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline