Monday, June 3, 2024
163
rated 0 times [  168] [ 5]  / answers: 1 / hits: 94541  / 13 Years ago, mon, march 12, 2012, 12:00:00

I was wondering if anyone can help me understand how exactly to create different Custom event listeners.



I don't have a specific case of an event but I want to learn just in general how it is done, so I can apply it where it is needed.



What I was looking to do, just incase some folks might need to know, was:



var position = 0;

for(var i = 0; i < 10; i++)
{
position++;
if((position + 1) % 4 == 0)
{
// do some functions
}
}

More From » event-listener

 Answers
4
var evt = document.createEvent(Event);
evt.initEvent(myEvent,true,true);

// custom param
evt.foo = bar;

//register
document.addEventListener(myEvent,myEventHandler,false);

//invoke
document.dispatchEvent(evt);


Here is the way to do it more locally, pinpointing listeners and publishers:
http://www.kaizou.org/2010/03/generating-custom-javascript-events/


[#86895] Sunday, March 11, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondd

Total Points: 620
Total Questions: 112
Total Answers: 94

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
raymondd questions
Thu, Apr 22, 21, 00:00, 3 Years ago
Thu, Jul 9, 20, 00:00, 4 Years ago
Thu, Apr 9, 20, 00:00, 4 Years ago
Thu, Jul 25, 19, 00:00, 5 Years ago
;