Suppose there is a function:
showPopup: function($el) { $el.addClass("current"); } It is necessary to add a line to it:
e.stopPropagation(); How to add event e to the parameters of this function?
Suppose there is a function:
showPopup: function($el) { $el.addClass("current"); } It is necessary to add a line to it:
e.stopPropagation(); How to add event e to the parameters of this function?
Just add the desired parameter to the function:
showPopup: function(event, $el) { event = event || window.event $el.addClass("current"); event.stopPropagation(); } In browsers that work on W3C recommendations, the event object is always passed to the handler as the first parameter. For example:
function doSomething(event) { // event - будет содержать объект события } element.onclick = doSomething; When the handler is called, the event event object will be passed to it as the first argument. You can assign it like this:
element.onclick = function(event) { // event - объект события } An interesting side effect is the possibility of using the event variable when assigning a handler in HTML:
<input type="button" onclick="alert(event)" value="Жми сюда не ошибешься"/> This works because the browser automatically creates a handler function with the given body, in which the first event argument.
In Internet Explorer, there is a global window.event object that stores information about the last event. And the handler argument simply does not exist.
That is, everything should work like this:
// обработчик без аргументов function doSomething() { // window.event - объект события } element.onclick = doSomething; Note that accessing the event when assigning a handler to HTML will still work. Such is the reliable and simple cross-browser access to the event object.
Source: https://ru.stackoverflow.com/questions/523092/
All Articles
Eventevent object. It is passed to the handler as an argument, IE creates an object globally inwindow.event(chrome supports it too, but this is rather an exception (FF does not set)). So you need to look exactly where the handler is assigned. - user207618