Questions tagged [custom-events]

The custom-events tag is an ambigious tag used when a question targets an event in an event-driven system created an maintained by the asker him or her -self.

The custom-events tag is an ambigious tag used when a question targets an event in an event-driven system created an maintained by the asker him or her -self. This tag should be used with care, and only if the question is about creating, triggering or handling an event that is not part of the default event-handling in the "system" or technology that otherwise is at question.

253 questions
141
votes
7 answers

Internet Explorer 9, 10 & 11 Event constructor doesn't work

I am creating an event, so use the DOM Event constructor: new Event('change'); This works fine in modern browsers, however in Internet Explorer 9, 10 & 11, it fails with: Object doesn't support this action How can I fix Internet Explorer (ideally…
118
votes
2 answers

JavaScript: Listen for attribute change?

Is it possible in JavaScript to listen for a change of attribute value? For example: var element=document.querySelector('…'); element.addEventListener( ? ,doit,false); element.setAttribute('something','whatever'); function doit() { } I would…
Manngo
  • 14,066
  • 10
  • 88
  • 110
82
votes
2 answers

Dispatch event with data

I'd like to dispatch an event that will pass some data to any event listeners that listen on that event. Considering a function that fires an event: function click() { const x = 'foo' document.dispatchEvent(new…
nicholaswmin
  • 21,686
  • 15
  • 91
  • 167
37
votes
3 answers

How do I create a custom event in an AngularJs service

I am working on an AngularJs project. I have a service which sets and removes events on some buttons. This service is utilized by another service which I do not want to interact directly with the buttons. However I would like a button click event to…
rmg.n3t
  • 951
  • 2
  • 10
  • 16
36
votes
5 answers

jQuery: How do I use event.preventDefault() with custom events?

How can I know in my triggering code that preventDefault has been called? $(document).trigger('customEvent', params); if (/* ??? */) doDefaultActions();
thorn0
  • 9,362
  • 3
  • 68
  • 96
27
votes
4 answers

Trigger event with parameters

This is pretty annoying. I want to just trigger an event in javascript. I need to pass the event object into the parameters as usual and an additional custom parameter. In jQuery, this would be super easy: $('#element').trigger('myevent',…
andy
  • 2,369
  • 2
  • 31
  • 50
16
votes
1 answer

Is it possible to list all custom events created?

I know it is possible to add an event listener to a custom event that I have created in Javascript, like this: window.addEventListener("MyCustomEvent", myFunction, false); But...Is it possible to list All custom events that exist at any point? The…
Oli C
  • 1,120
  • 13
  • 36
14
votes
2 answers

jQuery trigger not firing with bind() or on() for custom events

Can anyone tell me why this code would not be working? $('body').on('test', function() { alert('test'); }); $('body').trigger('test'); I'm using jquery-1.7.2.min. I do not get any errors, just nothing happens. I've tried putting the code inside…
iamface
  • 673
  • 1
  • 9
  • 27
12
votes
1 answer

Typescript: How to convert a string to a type

I am creating a bunch of web components and each of them can emit custom events. As an example here are two simple examples: //MyButton emits 'myButtonPressed' and detail of this type: interface ButtonDetailType { id: string; } //MySlider emits…
Marek Krzeminski
  • 1,308
  • 3
  • 15
  • 40
12
votes
1 answer

Difference between custom event and postMessage

In order to send a message to another document (let's say an iframe), you can use both postMessage and createEvent functions. Assume this: var event = document.createEvent('CustomEvent'); event.initCustomEvent("message", true, true, 'Hello…
Afshin Mehrabani
  • 33,262
  • 29
  • 136
  • 201
10
votes
2 answers

How to trigger custom event with jQuery?

I'm attaching a custom event handler to the body in jQuery's ready method. Afterwards I immediately trigger the custom event but nothing seems to happen. $(function(){ $("body").on("test", function(){ alert("test triggered"); } …
JJK
  • 179
  • 1
  • 2
  • 9
8
votes
0 answers

JavaScript dispatch CustomEvent: new or reuse

I want to dispatch a CustomEvent on different occasions. Most examples on the net create and dispatch CustomEvents only once. I want to know how to do it correctly. In this example the "A-Button" dispatches the same event over and over again. The…
htho
  • 1,549
  • 1
  • 12
  • 33
7
votes
0 answers

firebase custom events showing (not set) values

I am sending custom events in my firebase analytics and one of the event's values shows (not set). I have crossed check everything with logs and all, and the value and parameter name, nothing is going blank for this event, but still, in some cases,…
surbhi verma
  • 357
  • 4
  • 11
6
votes
2 answers

How to track which pages caused custom events in Google Analytics?

I have multiple pages being tracked by google analytics. On all these pages I have an outbound link for which I make a call to create a custom event - the action is named the same on all the pages. How can I see a breakdown of which pages caused…
aloo
  • 5,331
  • 7
  • 55
  • 94
6
votes
2 answers

Kendo MVVM and binding or extending custom events

I have a ComboBox in my page and I want to bind keypress event to my Kendo ComboBox when the cliend writes down any letter. As I understand kendo doesn't have any keypress event on ComboBox. I've found that kendo has something like this to bind…
Hirad Nikoo
  • 1,599
  • 16
  • 26
1
2 3
16 17