0

This code works when adding a dynamic table with data coming from an ajax request but can not remove the dynamic table. I code below shows whenever I click on a tree node, it should load its mysql table data into a HTML table.

     $("#treeNodes").on("select_node.jstree", function(event, data)
     {
           var node = data.rslt.obj;
           var nodeID = node.attr("id");
           event.stopImmediatePropagation;
           if(/leaf/.test(nodeID))
           {
                $(".tableData > *").remove(); // remove all table data (tr rows) before adding the new data and not working or firing off.
                addTableData(); // This function get the data from a mysql table and loads it into an HTML table.
           }

     });

     <table>
            <tbody class='tableData'></tbody>
    </table>

Would someone kindly show me how this code can recognize the newly added dynamic table data so it can be removed?

2 Answers 2

1

Try this instead:

$('.tableData').empty();

The empty() method removes all descendants and text from the element(s) it was called on.

Sign up to request clarification or add additional context in comments.

2 Comments

not working using $('.tableData').empty(), so how its not seeing the newly added table data but when I load the page table data, the $('.tableData').remove(), it works.
I had to go up one parent level and it worked using the table id instead of the tbody id
0

This should work:

$(".tableData").html("");

but what anOG wrote is faster. so use empty() instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.