Example: 'onclick', 'onmouseup'. Well and, accordingly, the ability to replace them.

NOT jquery interested. More precisely, implementation on native JS or on the earliest versions of the library.

Meaning: there is an element. We hang a new event on it and do stopImmediatePropagation. It's clear. But the problem is that our event, under certain conditions, worked FIRST. And interrupted the execution of the rest.

PS They are listeners. I would never have guessed in my life what listeners are.

  • @knes It is always better to use Russian words for new terms. - Nicolas Chabanovsky
  • With this, no one argues. But it so happened that Russian computers (for some reason, no one uses Russian computers, or even EVAs, although in fact they are synonyms) are a vanishingly small number, respectively, most of the programming languages ​​use English anyway. The person working with the language sees the familiar word "listener", which is part of the name of the function of working with events: addEventListener (), for example. To translate it into Russian it is necessary, including changing the word order. And in this case, the name changes beyond recognition ... - knes
  • See [cross-browser hanging] [1] - a class that facilitates work with events. Based on it, you can write the desired option. [1]: javascript.ru/tutorial/events/crossbrowser - ling

1 answer 1

to interrupt the execution of the rest is enough for example:

element = document.getElementById("element"); element.onclick = functionName; //теперь допустим что после отработки функции functionName //нам надо изменить обработчик function functionName() { //тут чета делаем this.onclick = anotherFunction; //цепляем новый обработчик // ну и естественно мы можем накинуть какой-то обработчик, или удалить // в теле этой же функции } 

About the fun finished, now about the sad one - it is impossible to get all the element handlers using standard language tools, as an option to write your function, but I'm not sure that after reading this code it will be useful. If it still will be necessary - the handler will have to write the method of getting all by itself.

PS: I hope correctly understood the task.

  • You gave a very good example. You have an onclick event. If the onmousedown handler hangs somewhere, the onclick will work AFTER the mouse click handler. And there are many such examples: pressing the buttons of the keyboard, clicking on the move, etc., when you have to execute handlers for several "simultaneous" ones. Here is the task to change the priority of execution, without climbing deep. Jikvery, by the way, uses an incompletely honest method: when hanging an event, she pushes it into an array-hint for what event was attached. In other words, the list of events and their priority is Ridonly. It is sad. - knes
  • By the way, since I began to understand all the delights of OOP in JavaScript on jQuery, I write only if they demand it from me :) - Zowie