kmunky
kmunky

Reputation: 15583

jquery UI sortable, how can i return the text of moved <li>?

what i'm trying to do is to return the text that is contained by the moved li, after the list item was moved. Is there a way to do that? thanks

EDIT:

i tried: $(ui.item).text() but i get an ui is not defined error (i imported just jquery.js, ui.core.js and ui.sortable.js , do i have to import something else?)

HTML

<ul id="sortable">
    <li><a href="" class="drag">text</a></li>
    <li><a href="" class="drag">another text</a></li>
    <li><a href="" class="drag">more text</a></li>
</ul>

JS

$(document).ready(function(){
     $('ul#sortable').sortable({
          handle:'.drag',
          axis:'y',
          update:function(){
               alert($(ui.item).text());
          }
     });
});

Upvotes: 4

Views: 4153

Answers (1)

Will Vousden
Will Vousden

Reputation: 33348

You haven't named any parameters in your callback function. You need to name them in order to use them:

$(document).ready(function(){
     $('ul#sortable').sortable({
          handle:'.drag',
          axis:'y',
          update:function(event, ui){
               alert($(ui.item).text());
          }
     });
});

Upvotes: 8

Related Questions