jquery bind stoppropagation callback context
-
27-01-2021 - |
Question
I am trying to prevent multiple events firing.
I'm using a callback function to pass an object, like this:
function init() {
var myObj = this.someObject;
$('#id').bind("blur keyup change", function (e, obj) {
return function () {
SomeFunction(e, obj);
}
} (this, myObj));
}
function SomeFunction(e, obj) {
e.stopPropagation();
//do something with the object
}
The error is that it can't find the function stopPropagation.
This is because I am assigning 'this' to e in the calling function.
How can I get access to the 'event' in SomeFunction?
Solution
I think you'll want to do something like this: http://jsfiddle.net/W47Ky/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow