[jQuery] add/remove and recalculate index

[jQuery] add/remove and recalculate index


i have an interface that allows user to add chapters and remove any chapter
from within the group. i'm having issues re-calculating the sort order.
currently if user adds four chapters (1,2,3,4), removes 2 and adds two more
the order becomes (1, 3,4,2,3). i know i need to so something with index
calculation...but how to is what is confusing me. this is the code that
performs the add remove.
$("#chapter-append").click(function() {
            var chapterCount = new Number($("#chapter-count").val());
                if (chapterCount <1) chapterCount=0;
        chapterCount = chapterCount +1;
         $("#chapter-count").val(chapterCount);
        
        var queryString = "add-chapter.php?chapter-number="+chapterCount;
        //alert(queryString);
$.get(queryString, function(html) {
// append the "ajax'd" data to the table body
$("ol#add-chapter").append(html);
                        $("ol#add-chapter li h4").bind('click', function() {
                                 var newChapter = "#chapter-"+chapterCount+"-container";
                             $(newChapter).remove();
                                    chapterCount = chapterCount -1;
                                     $("#chapter-count").val(chapterCount);
                                     return false;
                        });
                        $('textarea').autogrow({ minHeight: 144, lineHeight: 16});    
                        $('textarea.for-url').autogrow({ minHeight: 24, lineHeight: 16});
            });
return false;
    });
--
View this message in context: http://www.nabble.com/add-remove-and-recalculate-index-tp19750882s27240p19750882.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.