Reputation: 2760
I would like to know how can I fire an event from code. In jQuery to fire a "onchange" event you would simply $("selector").trigger("change"). Is there a way to do the same using WinJS.
[All suggestions of including jQuery will be discarded]
Thanks.
Upvotes: 1
Views: 2024
Reputation: 584
To fire and respond to a custom event do this.
fire the event
WinJS.Application.queueEvent({type: 'ev_login_completed'})
to respond to the custom event
WinJS.Application.addEventListener('ev_login_completed', function (e) {
// do stuff })
HTH
Upvotes: 0
Reputation: 1844
You can use event.initUIEvent
:
var button = document.getElementById('button');
var еvent = document.createEvent("UIEvents");
еvent .initUIEvent("click", false, false, window, 1);
button.dispatchEvent(еvent );
More info can be found here
Upvotes: 0
Reputation: 1165
In your ready function:
WinJS.Utilities.query("#yourSelector").listen("change", this.customClicked, false)
And then define customClicked function (can be named anything)
customClicked: function(eventInfo){
<!--do stuff -->
}
Upvotes: 0