Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ui selectable add/remove class on selected/unselected

Using jquery ui selectable , How it is possible to add a custom class on selected/selecting event and removing it on unselected/unselecting

I know we can style selection using CSS:.ui-selected{} but this deosnt help if I want to add custom class like ui-state-focus.

For Try, you can use my Fiddle.http://jsfiddle.net/bababalcksheep/CjT3r/2/. In this example i want to add/remove ui-state-focus class on selected/unselected

like image 309
django Avatar asked May 11 '26 08:05

django


1 Answers

If you are happy with using JavaScript for that, you can do it by handling the events:

  • selecting
  • selected
  • unselecting
  • unselected

To add/remove your custom classes.

Say you have classA for "selecting" and classB for "selected". Your selectable should be created like this:

$(".ui-splitselect-list").selectable({
    cancel: ".ui-splitselect-item .ui-splitselect-handle-drag",
    selecting: function (event, ui) {
        $(ui.selecting).addClass('classA');
    },
    unselecting: function (event, ui) {
        $(ui.unselecting).removeClass('classA');
    },
    selected: function (event, ui) {
        $(ui.selected).addClass('classB');
    },
    unselected: function (event, ui) {
        $(ui.unselected).removeClass('classB');
    }
});

Applied to your fiddle: http://jsfiddle.net/CjT3r/4/

like image 94
German Latorre Avatar answered May 13 '26 22:05

German Latorre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!