I have a jQuery slider (actually, a custom extension thereof) equipped with a handler for the slide
event, and this handler gets properly called when the slider is manipulated interactively, but not when I run
$("#slider").trigger("slide");
This command runs without error, but the slide
handler does not get called.
Why is this?
Do I need to pass a different argument to trigger to cause the slide
handler to be called?
EDIT: changed post's title to more closely reflect the question's motivation.
Working demo: http://jsfiddle.net/fLnmN/ or http://jsfiddle.net/F5ZCK/
Use .bind
like I used in the demo. you can use .on
as well like this: http://jsfiddle.net/u82Y5/
Some really helpful post here: Trigger a jQuery UI slider event
This should fit your need, :)
code
$('.slider').slider().bind({
change: function() {
alert('change triggered');
}
});
$('.slider').trigger('change');
OR
$('.slider').slider().on({
change: function() {
alert('change triggered');
},
slidechange: function() {
alert('slide trigger');
}
});
$('.slider').trigger('change');
$('.slider').trigger('slidechange');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With