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

  • Home
  • SEARCH
  • 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 6138759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:54:21+00:00 2026-05-23T17:54:21+00:00

Is there an way to delete everything after a particular div with javascript/jquery and

  • 0

Is there an way to delete everything after a particular div with javascript/jquery and replace with new code?

The DIV’s are generated dynamically and I want to be able to delete everything after
the last div which looks something like:

            <div class="galImage"> **div content** </div>
            /**delete everything after this point and replace with code below**/
        </div>
    </body>
</html>

I’ve tried $('.galImage').nextAll().remove(); which I found else where on stackoverflow but it doesn’t seem to have any effect – is nextAll() even a legitimate function?

  • 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-23T17:54:22+00:00Added an answer on May 23, 2026 at 5:54 pm

    Your question is a little unclear because you’ve posted what appears to be a fragment of markup.

    From what I can tell, you want to remove a textNode. Selectors and most jQuery traversal methods can’t find text nodes, but you can select it using the native API.

    var galimg = $('.galImage')[0];  // <-- get the DOM element
    
        // traverse to its parent, and remove the node that is after the galImage
    galimg.parentNode.removeChild( galimg.nextSibling );
    

    If there are additional nodes to remove, then you can use a loop:

    var galimg = $('.galImage')[0];
    var node;
    
    while( node = galimg.nextSibling ) {
        node.parentNode.removeChild( node );
    }
    

    Considering that you’re using jQuery, if there are indeed actual elements (not just text nodes) to remove, you should use .remove(), otherwise jQuery’s cache won’t be updated, which could cause a memory leak.

    var galimg = $('.galImage')[0];
    var node;
    
    while( node = galimg.nextSibling ) {
        $(node).remove();
    }
    

    Or if you want a full jQuery solution, you could do this:

    var galimg = $('.galImage');
    var nodes = galimg.parent().contents(); // <-- .contents() includes text nodes
    var idx = nodes.index( galimg );   // <-- get the index of galImage
    
    nodes.slice( idx + 1 ).remove();  // <-- take a slice of the nodes, starting at
                                      //       the index after the galImage
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an elegant way to delete all non-selected entries from a table after
Is there a way to delete a folder, lets call it FolderX from an
Is there an easy way to delete an element from an array using PHP,
Is there any way to find out if the user pressed the delete key
I need a way to recursively delete a folder and its children. Is there
Is there way in next piece of code to only get the first record?
Is there a way to enforce constraint checking in MSSQL only when inserting new
Is there any way to delete all records from all tables of a database
I like to know is there any way to delete a customer from back
is there way thats i can preselect an item when the page loads or

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.