210 of 264 menu

removeEventListener method

The removeEventListener method allows you to remove an event handler previously assigned via addEventListener. To do this, in the parameters you need to pass the event type and the same function that were passed when binding the event.

Syntax

element.removeEventListener('event type', function);

Example

Let's make it so that clicking on an element triggers only once:

<input type="button" id="button" value="click me"> let button = document.querySelector('#button'); button.addEventListener('click', func); // we assign the event function func() { alert('!!!'); button.removeEventListener('click', func); // remove it after clicking };

:

See also

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