its tough to diagnose without knowing what your variable "html"
returned by the $.ajax call is

but working up an example trying to simulate it, this works as
expected....  items stay in order of adding plus the <ol> items adjust
their indexes automatically

http://paste.pocoo.org/show/86671/




On Sep 30, 5:37 pm, claudes <[EMAIL PROTECTED]> wrote:
> 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-tp19750882s272...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to