This may be a shorter approach — I wrapped your text in the gap and added a “context” class to it. Then I can use selectors much easier to pull data into a JSON-ized object.
, HTML ( LI):
<li>
<span class="up">Up1</span>
<span class="down">Down1</span>
<span class="content">Item 1</span>
</li>
, , , .
: http://jsfiddle.net/Tn97g/
:
$("#submit").click(function() {
var items=$("#reOrder li");
var tosubmit=[];
$(items).each(function(index, e){
var nextItem = { "id": e.id, "val" : $(e).find(".content").text() };
tosubmit.push(nextItem );
});
alert(JSON.stringify(tosubmit));
});
, , . , !