causita
causita

Reputation: 1708

How to refer current UL LI on a sortable function

I'm using class to make <ul> sortable. Now, I need to get the <li>'s data-cube values in current <ul>.

Currently I'm using '#sortable2 li' but I would like to use something like ($(this) + ' li') but Is not working.

$("ul.droptrue").sortable({
   connectWith: "ul",
   receive: function (event, ui) {
      var sum = 0;
      var listItems = $("#sortable2 li");
      listItems.each(function (idx, li) {
      var product = $(li);
      sum += product.data("cube");
      });
   }
}); 

Upvotes: 1

Views: 80

Answers (1)

T J
T J

Reputation: 43156

You can access the <li>'s of receiver <ul> inside receive callback like

$(this).find("li");

or

$(this).children("li");

Upvotes: 1

Related Questions