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 6250869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:30:32+00:00 2026-05-24T13:30:32+00:00

SOLUTION removeChild: function(select) { $(select).nextAll().remove(); } I am trying to dynamically create a chain

  • 0

SOLUTION

removeChild: function(select) {
    $(select).nextAll().remove();
}

I am trying to dynamically create a chain of <select> boxes, here is an example function:

JQUERY:

getLanguages: function() {
    $.ajax({
        url: './db_scripts/get_languages.php',
        success: function( data ) {
            $('<select>', {
                id: 'languages',
                html: createOptions( data,'Language' )
            }).appendTo('#sidebar');
        }
    });
},

selects.getLanguages();
$('#languages').live('change', function() {
    selects.removeChild($(this));
    selects.getCategories();    
});

My HTML is just:

<div id="sidebar"></div>

Adding selects work perfectly. What I am trying to do is have another function that removes any children underneath the select that was changed. This way it removes all children <select> and the user can change the selection process anywhere in <select> tree. Here is an example of it working (try changing a top level option) http://philipimperato.com/mobileOrder

here is my removeChild() function:

removeChild: function(select) {
        alert('This is what is being passed in: ' + $(select).attr('id'));
        alert('This is the last child of the div, #sidebar: ' + $(select).parent('div').children('select:last-child').attr('id'));
        while($(select).parent('div').children('select:last-child') != $(select)) {
            alert('Same as first: ' + $(select).attr('id') + 'Same as 2nd: ' +$(select).parent('div').children('select:last-child').attr('id'));
            $(select).parent('div').remove($(select).parent('div').children('select:last-child'));
        }
    }

I have alerted stuff out for you convenience: Here is the website: InsanelyWeb

The function is not working and giving me a jQuery error: “c.replace is not a function” – I have no idea how to fix that. Does anyone have any advice for me? Thanks!
EDIT


Here is the function working in plain javascript (which I just figure out)

while(el.parentNode.lastChild != el) {
    el.parentNode.removeChild(el.parentNode.lastChild);
}

I am trying to convert that to jquery to do more stuff like hide() etc

while($(el).parent('div').children('select:last-child') != el) {
            $($(el).parent('div').children('select:last-child')).remove();
        }
  • 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-24T13:30:33+00:00Added an answer on May 24, 2026 at 1:30 pm

    I am not quite sure what you are trying to do in removeChild, but looking at your code, I think you misunderstood the way .remove() works in jQuery. It removed the elements selected (as in by the selector). So, if you want to remove the select element in removeChild, you can simply do:

    $(select).remove();
    

    Another method that also removes elements from the DOM is .empty(), which removes all children of the selected elements. So, if you want to remove all children of the #sidebar, you could do:

    $('#sidebar').empty();
    

    EDIT:

    Okay, here’s my 2nd try 🙂

    removeChild: function(select) {
        $(select).nextAll().remove();
    }
    

    Take a look at .nextAll(). It may be what you are after.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Solution: I've misinterpreted the example from SQL Books Online. Yes, that below the section
Made solution change: I am trying to display a html table of data.. In
I want to remove the temporary element which is created dynamically. x = document.createElement(DIV);
EDIT: Solution...email is a function within Validate which is a class so you need
UPDATED SOLUTION: With my particular problem, the sort call was inside a Render function
Solution -- WorkflowProject   -- Workflow1   -- Workflow2 -- WebProject (WAP)   -- App_Data     -- MyDatabase.vdb3
Solution to original problem (below) may have been discovered. I commented out <identity> ...
Solution for writing a program for keep secret photos. I have many secret photos
Programmatic solution of course...
The solution we developed uses a database (sqlserver 2005) for persistence purposes, and thus,

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.