Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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());
          }
     });
});
like image 634
kmunky Avatar asked Sep 15 '25 00:09

kmunky


1 Answers

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());
          }
     });
});
like image 179
Will Vousden Avatar answered Sep 17 '25 18:09

Will Vousden