jQuery UI draggable and adding class on drag event

Viewed 34007

I am trying to add a class to the draggable event using jQuery UI.

However the following code that I've written is not working as expected;

$(function () {
    $('ul.sortable div.draggable').draggable({
        start: function(event, ui) { ui.helper.addClass('move'); },
    });
});

Essentially I am trying to add a drop shadow (using the move class) to the div.draggable. What am I doing wrong as the drag event works, but the drop shadow does not appear?

Thanks in advance..

4 Answers

Try using the option classes: https://api.jqueryui.com/draggable/#option-classes

for example:

$( ".selector" ).draggable({
    classes: {
      "ui-draggable": "move"
    }
  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>

Related