I have a table like this:
<table id='inventory_table'>
<tr id='no_items_avail'>
<td>
There are no items in the database.
</td>
</tr>
</table>
And I want to get rid of it with jQuery like this:
$('#inventory_table tbody tr#no_items_avail').remove();
However it doesn’t seem to be working at all. What am I doing wrong?
Edit: Also, the row above was originally inserted into the DOM with another jQuery call:
$('#inventory_table tbody').append("<tr id='no_items_avail'.......
If that helps. And, running:
alert($('#no_items_avail').text());
yields “There are no items in the database.” as expected.
My guess is that you are using the same ID more than once in the same document? Because this works perfectly for me on IE8 (compatibility mode), FF and Chrome.
Of course it doesn’t need to be that complex as this works perfectly:
Just remember that IDs have to be unique and duplicating them is a common reason why this kind of thing fails.