views:

136

answers:

1

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());
          }
     });
});
+1  A: 

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());
          }
     });
});
Will Vousden
many thanks @Inquisitor, i didn't know that. Thanks for your help
kmunky