Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't $("#slider").trigger("slide") result in calling the slide handler?

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.

like image 546
kjo Avatar asked Mar 23 '23 03:03

kjo


1 Answers

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');
like image 111
Tats_innit Avatar answered Apr 19 '23 03:04

Tats_innit