Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3753492
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:24:01+00:00 2026-05-19T09:24:01+00:00

Hi folks need some help adjusting some JQ. This all works (may not be

  • 0

Hi folks need some help adjusting some JQ. This all works (may not be perfect to purists) but at least for me it works as it should. However, I would like to add some “additional functionality” which I think needs me to use the each index function, but I don’t have a clue how/what/why/where ….

The code dynamically adds <div>‘s and hides the previous to create simple “pages” (if you want to call them that) and a simple pagination for the created <div>‘s. The additional functionality I would like to add is to delete a div – OK delete is NP just “remove()” the appropriate <div>, but can I dynamically “reindex” using “each”?

e.g. if I have 4 “pages” I would have (in code below) 8 div’s – pageno is the var used to get the length/number of pages (again code below).

<div class="pagedisplay" id="rhcol0">text</div>
<div class="pagedisplay" id="lhcol0">text</div>
<div class="pagedisplay" id="rhcol1">text</div>
<div class="pagedisplay" id="lhcol1">text</div>
<div class="pagedisplay" id="rhcol2">text</div>
<div class="pagedisplay" id="lhcol2">text</div>
<div class="pagedisplay" id="rhcol3">text</div>
<div class="pagedisplay" id="lhcol3">text</div>

If I then remove pageno==2 i.e.

<div class="pagedisplay" id="rhcol2">text</div>
<div class="pagedisplay" id="lhcol2">text</div>

is it possible to dynamically “reindex” the remaining divs so I would then have:

<div class="pagedisplay" id="rhcol0">text</div>
<div class="pagedisplay" id="lhcol0">text</div>
<div class="pagedisplay" id="rhcol1">text</div>
<div class="pagedisplay" id="lhcol1">text</div>
<div class="pagedisplay" id="rhcol2">text</div>
<div class="pagedisplay" id="lhcol2">text</div>

In other words the pageno still remains in order with no “gaps” as above NOT

<div class="pagedisplay" id="rhcol0">text</div>
<div class="pagedisplay" id="lhcol0">text</div>
<div class="pagedisplay" id="rhcol1">text</div>
<div class="pagedisplay" id="lhcol1">text</div>
<div class="pagedisplay" id="rhcol3">text</div>
<div class="pagedisplay" id="lhcol3">text</div>

Where pageno==2 has been removed?

Here is my current code:

$(document).ready(function() {
$('#addpage').click(function(){
var pageno = $('.pagebut').length;
$('.pagedisplay:visible').hide();   
$('#lhcol').append( '<div class="pagedisplay" id="lhcol'+pageno+'">'+pageno+'</div>' );
$('#rhcol #slider_holder').before( '<div class="pagedisplay" id="rhcol'+pageno+'">'+pageno+'</div>' );
$('#rhcol #slider_holder').show();  
$('#rhcol #slider_holder').append( ' <a href="#" class="pagebut">'+pageno+'</a> ' );
return false;
});
$('.pagebut').live('click',function(){
var pageno = $(this).html();
$('.pagedisplay').hide();
$('#lhtest'+pageno).show();
$('#rhtest'+pageno).show();
return false;
});
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T09:24:02+00:00Added an answer on May 19, 2026 at 9:24 am

    I altered each of the functions a bit. Something •like• this should work. I don’t know if this exactly will work. I’m using jQuery’s nextAll to grab siblings that follow a given element, and then each to iterate through them and subtract 1 from the page number. Make sense?

    I also changed things a little to reduce the number of elements that have to be changed. The paging/remove buttons have a direct number to use for their work, instead of having to work through every element in the page and change numbers around.

    $(document).ready(function() {
      $('#addpage').click(function(){
        var pageno = parseInt($('.pagebut').last().html()) + 1;
        $('.pagedisplay:visible').hide();   
        $('#lhcol').append( '<div class="pagedisplay" id="lhcol'+pageno+'">'+pageno+'</div>' );
        $('#rhcol #slider_holder').before( '<div class="pagedisplay" id="rhcol'+pageno+'">'+pageno+'</div>' );
        $('#rhcol #slider_holder').show();  
        $('#rhcol #slider_holder').append( ' <a href="#" class="pagebut" id="pagebut'+pageno+'" data-page_number="'+pageno'">'+pageno+'</a> ' );
        $('#rhcol #slider_holder').append( ' <a href="#" class="remove" id="remove'+pageno'" data-page_number="'+pageno'">Remove '+pageno+'</a> ' );
        return false;
      });
      $('.pagebut').live('click',function(){
        var pageno = $(this).data('page_number');
        $('.pagedisplay').hide();
        $('#lhtest'+pageno).show();
        $('#rhtest'+pageno).show();
        return false;
      });
      $('.remove').live('click', function() {
        var page_number_to_remove = parseInt($(this).data('page_number'));
        var total_pages = $('.pagebut').length;
        $(this).nextAll('.pagebut').each(function(index, elem) { var el = $(elem); el.html(parseInt(el.html()) - 1)});
        $(this).nextAll('.remove').each(function(index, elem) { var el = $(elem); el.html('Remove '+ parseInt(el.html().replace(/Remove /,'')) - 1)});
           $('remove'+page_number_to_remove, 'pagebut'+page_number_to_remove, 'rhcol'+page_number_to_remove, 'lhcol'+page_number_to_remove).remove();
        return false;
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

folks! I need some help with organizing database for application and I have no
Folks, I need to accomplish some sophisticated web crawling. The goal in simple words:
I am hoping some smart folks can help me here. I'm out of my
I feel like this should be really really simple, but I'm completely stuck! In
I need simple CMS to allow non-tech folks edit some static text in app
I'm very new to c and programming and need some help. In c on
I have this regex which some kind folks on SO helped me with yesterday.
I’m not sure this is the best example, but here goes. Let’s say I
folks, i need to retrieve colors of an image.. how to retrieve it?
Folks, I need to maintain a C#/.Net desktop application. So, I need to set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.