Lewis
Lewis

Reputation: 244

Jquery Sortable .toArray script error

Could someone PLEASE, for the love of god, tell me why this works:

$(document).ready(function(){
  $('#clause_sort').sortable({
  update: function(event, ui) {
    var clauseOrder = $(this).sortable('toArray').toString();
        alert(clauseOrder);     
        }
        });         
}); // End of ready

And this, inexplicably doesn't:

$(document).ready(function(){

$('#clause_sort').sortable();

$("#generate").click(function(){
var clauseOrder = $("'#clause_sort").sortable('toArray').toString();
alert(clauseOrder);
});

}); // End of ready

I've not included the HTML, but #clause_sort is a nested set of Divs (that do indeed become sortable) and #generate is a button. In the first example everything works, and when the order is changed it instantly generates an alert with a string containing the clause order.

I only need the order, however, when the user clicks a button. According to everything I can find on the topic, the second code should work. Instead clicking the button generates an a script error.

I have considered simply sticking with the first method, and having a global variable that just keeps getting updated. The problem with this is: 1) the user may not change the order of the list at all (so the variable remains unset); and 2) its driving me insane why it won't work, so I want an answer anyway!

Any help is greatly appreciated.

Upvotes: 0

Views: 750

Answers (1)

YD1m
YD1m

Reputation: 5895

Replace for:

var clauseOrder = $("#clause_sort").sortable('toArray').toString(); 
// remove redundant quote

Upvotes: 1

Related Questions