document ready function var resort function var jQuery each paragraphs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$(document).ready(function() {
var resort = function()
{
var i = 0;
jQuery.each($('.paragraphs .paragraph'), function() {
$(this).children('div.text').children('input.position').val(i++);
});
}
$(".paragraphs .text .up").click(function(){
var div = $(this).parent('div.text').parent('div.paragraph');
div.insertBefore(div.prev());
resort();
return false
});
$(".paragraphs .text .down").click(function(){
var div = $(this).parent('div.text').parent('div.paragraph');
div.insertAfter(div.next());
resort();
return false
});
});