Trigger a jQuery UI slider event


Solution 1


$slider = $('#slider');
$slider.slider('option', 'change').call($slider);

Not ideal but gets you working!

alt text

Solution 2

I know this is way past the post date, but I wanted to post to provide this solution to anyone that stumbles upon this post.

You can accomplish event triggering by doing something along the lines of:



Unfortunately you cannot define the functions as options within the init object, however, I think it ends up looking cleaner and is more straight forward and correct than the other answer using the call method (i.e. it does use the event system).

And yes, the callbacks you define here will be called on normal operation (changing the position of the slider in this case) as it normally would. Just make sure you use the correct event type names from the UI documentation.

If you want to add multiple events at once, remember you can provide an object to bind using the event names as keys:

    slidestart  : function(event,ui) {...},
    slidechange : function(event,ui) {...},
    slidestop   : function(event,ui) {...},


This is noted in the documentation, although, it is not very clear. Took me developing a couple plugins on my own to really understand the UI event system.


Solution 3

A good approach is simply to change the value of the slider. The slider's own change method should then respond to the change of value. For instance:

var newValue=5;
$('#slider').slider("value", newValue);

Solution 4

This maybe resurrecting an old thread, but was just having a similar experience. The solution that I came up with (because the thought of calling slider(...) multiple times was not appealing):

$slider.slider('option', 'slide').call($slider, event, ui);

With $slider being bound to the $(selector).slider(...) initialization.

Solution 5

Yet another way, which is handy for UI widgets like autocomplete, is to access the event directly via the data method. JQuery stores all of its event hookup info using .data("events"), so if you use that property you can access the events directly. On some UI components (eg. autocomplete) the events aren't even attached to the main element, they're attached to the UI object itself. Luckily, that UI object is also available in data.

So, without further ado, here's how you'd invoke the autocomplete's select event:


Or, (getting back to sliders) to trigger a slider's change:


Trigger is still the best way of course, since it actual utilizes the event system, but on the more complex widgets where "$(elem).trigger" won't be enough, this approach is handy.

* EDIT *

Just figured out that you actually can "trigger" the event properly with this method, using the widget's "secret" _trigger property. For example:

$("#autoComplete").data("autocomplete")._trigger("select", fakeEvent, fakeItem)

Hope this helps someone.

Author by


PHP + Javascript programmer. Twitter

Updated on July 09, 2022


  • Greg
    Greg over 1 year

    How can I trigger a change event on a jQuery UI slider?

    I thought it would be


    but that does nothing.

    Full example script follows:

    <link href="" rel="stylesheet" type="text/css"> 
    <script src="" type="text/javascript"></script> 
    <script src="" type="text/javascript"></script> 
    <script src="" type="text/javascript"></script> 
    <div id="slider"></div>
    <script type="text/javascript">
        $('#slider').slider({change: function() { alert(0); }});
        // These don't work

    I would expect this to alert "0" when the page loads

    • karim79
      karim79 over 14 years
      Why is it that seemingly 95% of the time what the jQuery UI docs say does not work :) ?
  • Greg
    Greg over 14 years
    Eww ugly :p +1 though 'cause it works. I'll give it a bit longer in case John Resig stops by...
  • Greg
    Greg over 14 years
    I've edited your answer because while it worked for my test script it didn't work for the real one - "this" was coming out wrong.
  • Patonza
    Patonza over 13 years
    This is not a solution. Calling the function associated with the event is not the same as triggering the event itself, e.g. you have to manually pass the parameters (even if this case it's only the object, other events may have more parameters)
  • Brian McAllister
    Brian McAllister almost 12 years
    Thanks for pointing out the _trigger() function, worked really well for me.
  • Eugene Gluhotorenko
    Eugene Gluhotorenko over 11 years
    $slider.slider('option', 'change') returns $slider object not a function
  • SUN Jiangong
    SUN Jiangong about 11 years
    @redsquare When i try to trigger "slide" event with $slider.slider('option', 'slide').call($slider); I get "event" and "ui" undefined.
  • sites
    sites over 10 years
    How ui and event are initialised?
  • Felipe Castro
    Felipe Castro over 10 years
    @charlessun I had the same problem, and got it working providing those two params manually: $slider.slider('option', 'slide')(null, { value: $slider.slider('value') }) (first param is 'event' and second is 'ui'). Jquery UI version 1.10.2
  • raveren
    raveren over 10 years
    Seriously, jqueryUI is such a complete mess, anything slightly advanced and you're resorted to hacks. Not only slider either - the whole library is consistently shitty.
  • lopsided
    lopsided over 10 years
    I like this solution as it triggers the actual slide event. Worth noting now that it is no longer data("slider") it is data("uiSlider")
  • Adrian Bartholomew
    Adrian Bartholomew about 10 years
    @Raveren - Then don't use it - make one yourself.
  • raveren
    raveren about 10 years
    I no longer do, I've resorted to single-serving libraries that just work.
  • hrabinowitz
    hrabinowitz about 10 years
    The approach you've mentioned works for me, as does that of Felipe Castro. But I don't understand why I cannot just say $slider.trigger("slide", ui);
  • Wayne Weibel
    Wayne Weibel about 10 years
    I continued to play around with it all and the only explanation I could see was that the 'slide' event was not on the $slider object, but rather an element of $slider (if that makes sense). You first had to retrieve the desired function of the 'slider' (not $slider) object then call it with the appropriate parameters. The 'slider' is actually several DOM elements so there is not a true trigger point for the function.
  • Ben
    Ben almost 10 years
    But this will not trigger slide event?
  • andy
    andy almost 10 years
    this gives me "TypeError: ui is undefined"
  • radtek
    radtek over 9 years
    If its a multi handle slider use this instead: $slider.slider('option', 'slide')(null, { values: $slider.slider('values')})
  • robabby
    robabby over 9 years
    @lopsided Thank you! Do you know where that change is documented?
  • Elise Chant
    Elise Chant about 9 years
    i'm sorry, but you really can't use the private methods. Who knows what will happen to them for one thing
  • Alex. P.
    Alex. P. almost 8 years
    I'd say this should be the correct answer. I can't think of a use case where it is imperative that you trigger an event without changing the value of the slider. Let the slider dispatch the events as they were defined when it was constructed.
  • john-jones
    john-jones over 7 years
    @Felipe Castro. Maybe you should post this as a separate answer as it was the solution in my case.
  • Lisa DeBruine
    Lisa DeBruine almost 7 years
    I have such a case. I'm dynamically changing the colour of optional grid lines on an image with a slider. The grid lines and slider disappear if I untick a checkbox for the grid lines option. I want the change event on the slider to fire to to redraw the lines if I tick that checkbox to re-show grid lines, but I want the last colour chosen. Luckily, the change event still fires even if you set the value to itself, although the code is really ugly: $('#slider').slider('value', $('#slider').slider('value')); )
  • Justas
    Justas over 5 years
    In the newer versions this works: $('#slider').trigger('slide');
  • Harm
    Harm over 4 years
    Do not use bind, it is deprecated in version 3.0. See jquery ui documentation (