css selector syntax for deleting td element with jQuery

2

Some way to use jquery and selectors in a similar way?

$("#tabela td").empty();

I need to delete only the tr lines that contain td of a table like this, but not the tr lines that have th elements.

As I'm doing, it deletes the td , but not the tr that contains td .

<table id = "tabela">
    <tr>
        <th>title</th>
    </tr>
    <tr>
        <td>teste</td>
    </tr>
</table>
    
asked by anonymous 25.07.2014 / 15:14

3 answers

3
___ erkimt ___ css selector syntax for deleting td element with jQuery ______ qstntxt ___

Some way to use jquery and selectors in a similar way?

$("#tabela td").closest('tr').empty(); // ou .remove();

I need to delete only the .closest('tr') lines that contain tr of a table like this, but not the %code% lines that have %code% elements.

As I'm doing, it deletes the %code% , but not the %code% that contains %code% .

$("#tabela td").closest('tr').empty(); // ou .remove();
    
______ ___ azszpr26587

I suggest doing as started and add %code% so it rises to the element %code% and can remove it.

%pre%

Example: link

    
______ azszpr26582 ___

I had not used it like this before, but I think it's okay to continue using it. In my case, I usually use the closest ( link ) and remove it ( link ), passing the element that received the click.

For example:

%code%

%code%

    
______ azszpr26585 ___

Your selector is almost correct.

For the HTML markup below

%pre%

This JS code solves the problem

%pre%

Example: link

Edit1 to meet the requirement

    
___
25.07.2014 / 16:10
0

I had not used it like this before, but I think it's okay to continue using it. In my case, I usually use the closest ( link ) and remove it ( link ), passing the element that received the click.

For example:

<!-- tabela --> <table> <tr> <td>Asdf</td> <td><a onclick="excluir(this)">Excluir</a></td> </tr> </table>

<!-- script --> // Irá encontrar a primeira ocorrência TR a partir do elemento (no caso, o link) e fazer a ação que mandarmos (no caso, excluir a tr toda). function excluir(element){ $(element).closest('tr').remove(); }

    
25.07.2014 / 16:00
0

Your selector is almost correct.

For the HTML markup below

<table id="tabela">
    <tr>
        <th>Linha com TH</th>
    </tr>
    <tr>
        <td>Linha com TD</td>
    </tr>
</table>

This JS code solves the problem

$("#tabela td").closest("tr").remove();

Example: link

Edit1 to meet the requirement

    
25.07.2014 / 16:03