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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:34:24+00:00 2026-05-23T00:34:24+00:00

i have to switch in between two table as per users choice i can

  • 0

i have to switch in between two table as per users choice i can do it using table object model but there is problem with it as i remove one table and load another it will work but next time when i have switch back to first it will not get table ids and its not working.

while working with DOM like this

var tbl1  = document.createElement("table");

tbl1.setAttribute('id','shorttable');

for delete i am using below java script

var b = document.getElementById('shorttable');

document.removeChild(b);

but giving me exception

uncaught Error: NOT_FOUND_ERR: DOM Exception

is there any way to do this using DOM?

@lonesomeday thanks for ur reply but its not working when i call it from other function?
what i am trying is like this.

  <html>
  <head>
  <title>test dom</title>
  <script>

  function trackmode() 
{
    // i have to delete other table from this function where it is not working  
    var b = document.getElementById('shorttable');
    alert(b);
    b.parentNode.removeChild(b);

    var body = document.getElementsByTagName("body")[0];


    // creates a <table> element and a <tbody> element
    var tbl     = document.createElement("table");
    tbl.setAttribute('id','tracktable');
    var tblBody = document.createElement("tbody");

    // creating all cells
    for (var j = 0; j < 2; j++) {
        // creates a table row
        var row = document.createElement("tr");

        for (var i = 0; i < 2; i++) {
            // Create a <td> element and a text node, make the text
            // node the contents of the <td>, and put the <td> at
            // the end of the table row
            var cell = document.createElement("td");
            var cellText = document.createTextNode("cell is row "+j+", column "+i);
            cell.appendChild(cellText);
            row.appendChild(cell);
        }

        // add the row to the end of the table body
        tblBody.appendChild(row);
    }

    // put the <tbody> in the <table>
    tbl.appendChild(tblBody);
    // appends <table> into <body>
    body.appendChild(tbl);
    // sets the border attribute of tbl to 2;
    tbl.setAttribute("border", "2");
}


function shortenmode() 
{

     var b = document.getElementById('tracktable');
b.parentNode.removeChild(b);

    var body1 = document.getElementsByTagName("body")[0];
    // creates a <table> element and a <tbody> element
    var tbl1  = document.createElement("table");
    tbl1.setAttribute('id','shorttable');
    var tblBody1 = document.createElement("tbody");

    // creating all cells
    for (var j = 0; j < 2; j++) {
        // creates a table row
        var row = document.createElement("tr");

        for (var i = 0; i < 2; i++) {
            // Create a <td> element and a text node, make the text
            // node the contents of the <td>, and put the <td> at
            // the end of the table row
            var cell = document.createElement("td");
            var cellText = document.createTextNode("cell is row "+j+", column "+i);
            cell.appendChild(cellText);
            row.appendChild(cell);
        }

        // add the row to the end of the table body
        tblBody1.appendChild(row);
    }

    // put the <tbody> in the <table>
    tbl1.appendChild(tblBody1);
    // appends <table> into <body>
    body1.appendChild(tbl1);
    // sets the border attribute of tbl to 2;
    tbl1.setAttribute("border", "2");

         //here it will work
    //var b = document.getElementById('shorttable');
    //alert(b);
    //b.parentNode.removeChild(b);

    //myP.removeChild(myTextNode);
}


  </script>
  </head>
  <body >
 <button type="button" name="website" onclick=trackmode() > track</button>
 <button type="button" name="website1" onclick=shortenmode() > short </button>
 </body>
</html>
  • 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-23T00:34:25+00:00Added an answer on May 23, 2026 at 12:34 am

    To remove an element, you need to remove it from its parent, not from the document. So:

    b.parentNode.removeChild(b);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can switch between windows with C-x o, but if I have opened multiple
For as long as I can remember I have avoided using switch statement fall-through.
I have been trying to explain the difference between switch statements and pattern matching(F#)
I have written a site in Prototype but want to switch to jQuery. Any
I have problem in some JavaScript that I am writing where the Switch statement
i have two iphone apps and want to they able to switch via a
I'm giving my first steps on Python. I saw that we don't have switch
I have a coworker who is looking to switch from InteilliJ Idea to Eclipse,
I have an executable that depending on the command line switch supplied looks something
I have some code that looks like this: someFunc(value) { switch(value){ case 1: case

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.