JQuery UI widgets (i.e. slider) and launching your own custom event handlers

If we bind an event clickto a link as

$("linkSelector").click(function(){ ... });

then we can also easily force this event handler, even if the user hasn’t clicked the link.

$("linkSelector").click(function() { ... }).click();

But in my case, I'm using a jQuery Slider widget , which has an event slideto which an event handler can bind. I wonder how we can programmatically execute our events?

I tried, but none of them work:

$("sliderSelector").slider({ slide: function(){ ... } }).slide();
$("sliderSelector").slider({ slide: function(){ ... } }).slider("slide");
$("sliderSelector").slider({ slide: function(){ ... } }).trigger("slide");

I know that I could use a named function instead of an anonymous one, but I do not consider this a solution, because I can call the function with any arguments that I want when the event fires slide, to ensure the correct values ​​set by the slider.

+3
2

, :

var s = $("sliderSelector").slider({ slide: function(evt, ui){ ... } });
s.slider("option", "slide").call(s, null, { values: s.slider("values") });

, , . , , ui.values, , .

, .slider(), .

+9

.

.bind() ( .on jQuery) , , , , .trigger().

, , - .

+2

All Articles