user1525703
user1525703

Reputation: 37

I cannot delete the rows using jquery

$('#DepartmentNameDropdown').change(function(){

    $.ajax({
        type: 'post',
        dataType: 'json',
        url: "http://localhost:8081/crownregency/getInfoSearch.php",
        data: {id: $('#DepartmentNameDropdown').val()},
        success: function(data){
                $("tbody #tbody").find("tr:gt(0)").remove();;
                for (var i = 0; i < data.length; i++)
                {
                    $row = "<tr><td>" +data[i]['fname']+ "</td><td>" +data[i]['lname']+ "</td><td>" +data[i]['job']+ "</td><td>" +data[i]['loc']+ "</td></tr>";
                    $('#usersTable').find("tbody").after($row);
                }

            }
        });                                          
    });

this is my jquery for display, when i change the departmentnamedropdown value i want to clear the table but leave the thead intact.

<table width="581" border="1" id="usersTable">
<thead>
    <th width="25%">First Name</td>
    <th width="25%">Last Name</td>
    <th width="25%">Job Title</td>
  <th width="25%">Location</td>
 </thead>
 <tbody id="#tbody"></tbody>
</table>

this is my table, can someone help. thanks

Upvotes: 0

Views: 106

Answers (2)

thecodeparadox
thecodeparadox

Reputation: 87073

change

<tbody id="#tbody"></tbody>

to

<tbody id="tbody"></tbody> <!-- remove the # sign-->

and change the jQuery to:

$("#tbody").find("tr:gt(0)").remove();

Upvotes: 0

Guffa
Guffa

Reputation: 700262

Your selector is looking for an element with id="tbody" inside the tbody element. Remove the space:

$("tbody#tbody")

The id should be unique in the page, so you should be able to use just:

$("#tbody")

Upvotes: 1

Related Questions