The reason trigger('slide')
doesn't work is because when you set your slide
callback, the slider does not register a slide event with the DOM element. Instead, it delegates generic mouse events to the DOM element and then translates them into your callbacks internally.
Unfortunately, this leaves you to work around that API. Tats_innit's answer binds events directly to the DOM element, but they don't tie into the slider API. You'll have to call your callback function within these handler function.
If you have your callbacks accessible, you can call them directly, as follows:
$('#slider').slider({
'slide': onSlide
}).on('slide', onSlide);
If you prefer to define the callback functions inline, you can retrieve them as follows:
$('#slider').slider({
'slide': function(event, ui) { /* ... */ },
}).on('slide', function() {
$(this).slider('option', 'slide').apply(this, arguments);
});
Needless to say this is painfully redundant, but again, it's a workaround.
On a side note, remember that triggering events individually skips over other events that would be called in succession when they come from the user. For example, triggering a stop
event would miss the slide
event that the user would generate as he is adjusting the slider. You might consider "justifying" the external event binding by creating a custom event that dispatches multiple events on your behalf (e.g., $('#slider').trigger('setvalue')
).