J
J
Joirvy2019-03-21 16:53:25
JavaScript
Joirvy, 2019-03-21 16:53:25

How to remove the onkeypress handler?

I am attaching a handler function to input.

input.onkeypress = function(evt) {
      //some code      
}

How can I remove it in another function? Recording in the form:
input.onkeypress = function(evt) {
      evt.preventDefault();  
}

didn't help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
DanKud, 2019-03-21
@BeatTimy

function test() {
    alert('событие активно');
}

input.addEventListener('keypress', test);

input.removeEventListener('keypress', test);

Example - https://codepen.io/anon/pen/LaXRJq

S
sim3x, 2016-12-10
@sim3x

guess.scritch.org/%2Bguess/?url=gl-nutrition.ru
Webserver Nginx 1.9.12 50%
Framework Yet another PHP framework? Or maybe just a static site?
Language PHP 5.6.18-pl0-gentoo 90%

S
shikakker, 2016-12-10
@shikakker

bootstrap some 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question