D
D
Dubrovin2018-03-02 04:57:44
JavaScript
Dubrovin, 2018-03-02 04:57:44

Is there any way to remove the event handler inside the callback function immediately after execution?

element.addEventListener( 'mousedown', () => {
    window.addEventListener( 'mouseup', () => {
        //сделать что-то;
        //а вот тут удалить обработчик на window, пока не будет сделан следующий клик на элементе
    } );
} );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Tolerant, 2018-03-02
@Dubrovin

addEventListener and removeEventListener

const onClick = () => {
 console.log("Hello World");
  window.removeEventListener('click', onClick);
});
window.addEventListener('click', onClick);

zyzh did not notice the comment above.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question