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

  • SEARCH
  • Home
  • 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 3303750
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:59:23+00:00 2026-05-17T20:59:23+00:00

I’m trying to remove a row from a table when I click a specific

  • 0

I’m trying to remove a row from a table when I click a specific row column. I’m using .live() so that I can remove rows added from a ajax request. It works fine, my problem is, the table comes from php with two rows, I can then insert new ones and remove them, but when I remove one of the rows that came with php, it remove all rows from the table.

PHP:

<table id="listaEquipamentos">
<?php 
    if($this->listaEquipamentos){
     foreach ($this->listaEquipamentos as $equipamento) { 
      $UF = trim($equipamento['siglaUF']);?>
     <tr>
      <td><?php echo $equipamento['siglaUF'];?></td>
      <td><?php echo $equipamento['siglaLocalidade'];?></td>
      <td><?php echo $equipamento['siglaEstacao']?></td>
      <td><?php echo $equipamento['nomeEquipamento'];?></td>
      <td><?php echo $something; ?></td>
      <td align="center">
       <?php echo "<input class='bot1' type='button' value='X'> " ?>
      </td>
     </tr>
     <?php } ?>
    </table>

JavaScript:

$('#listaEquipamentos tr > td:nth-child(6)').live("click", function(){
 if(confirm("Do you want to remove this row?")){
  $(this).parent('tr').remove();
 }
});

$("#btnAddEquipamento").click(function(){
 var ok = 1;
 if($("#slcUF").val() == 0){
  alert("UF em Branco");
  ok = 0;
 } else if($("#slcLocalidade").val() == 0){
  alert("Localidade em Branco");
  ok = 0;
 } else if($("#slcEstacao").val() == 0){
  alert("Estacao em Branco");
  ok = 0;
 } else if($("#txtEquipamento").val() == ""){
  alert("Equipamento em Branco");
  ok = 0;
 } else if($("#slcEquipamento").val() == "0"){
  alert("Equipamentoo em Branco");
  ok = 0;
 }
 if(ok){
  if($("#slcAbrangencia").val() != ""){
   var toadd = $('#slcEquipamento option:selected').text();
   var existe = 0;

   $("#divListaEquipamento tr>td:nth-child(4)").each(function(index){
    if( $(this).text() == toadd)
     existe = 1;
        });

   if(existe != 1){

    var uf = $('#slcUF option:selected').text();
    var loc = $('#slcLocalidade option:selected').text();
    var est = $('#slcEstacao option:selected').text();
    if($("#slcEquipamento").val() > 0){
     $("#hdnEquipamento").val($("#slcEquipamento").val()+"||"+$('#slcEquipamento option:selected').text());
    }else{
     var equip = $('#txtEquipamento').val().substr(0,15);
     $("#hdnEquipamento").val(equip);
    }
    var tempLoc = loc.split("-");
    var tempEst = est.split("-");
    $("#hdnUF").val(uf.substr(0,2));
    $("#hdnLocalidade").val(tempLoc[0]);
    $("#hdnEstacao").val(tempEst[0]);
    $.post("/aplicacao/jm/index.php/janela/addequipamento", $("#frmNovaJanela").serialize(),
         function(data){
        if(data[0] != null){
         $(".tabResultado1 > tbody>tr:last").prev().append("<tr><td>"+data[1]+"</td><td>"+data[3]+"</td><td>"+data[5]+"</td><td>"+data[7]+"</td><td>"+data[8]+"</td><td><input class='bot1' type='button' value='X'></td></tr>");
         var total = parseInt($("#divListaEquipamento tr:last > td:nth-child(5)").text()) + parseInt(data[8]);
         $("#divListaEquipamento tr:last > td:nth-child(5)").text(total);
        }else alert("Problema ao gravar equipamento.")
        }, "json");    
   }else{
    alert('O Equipamento '+toadd+' já está na lista.');
   }
  }else{
   alert ("Favor Selecionar a Abrangencia.");
  }
 }
});

I’v already tried:

$(this).parent('tr').remove();
$(this).parents('tr').remove();
$(this).parent().parent().remove();
$(this).closest('tr').remove();
  • 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-17T20:59:23+00:00Added an answer on May 17, 2026 at 8:59 pm

    I was probably doing something stupid! I’v changed some things, and now it works!

    $('#listaEquipamentos tr > td:nth-child(6)').live("click", function(){
        if(confirm("Deseja remover esta linha?")){
            $(this).parent('tr').remove(); ;
        }
    });
    
    $("#btnAddEquipamento").click(function(){
        var ok = 1;
        if($("#slcUF").val() == 0){
            alert("UF em Branco");
            ok = 0;
        } else if($("#slcLocalidade").val() == 0){
            alert("Localidade em Branco");
            ok = 0;
        } else if($("#slcEstacao").val() == 0){
            alert("Estacao em Branco");
            ok = 0;
        } else if($("#txtEquipamento").val() == ""){
            alert("Equipamento em Branco");
            ok = 0;
        } else if($("#slcEquipamento").val() == "0"){
            alert("Equipamentoo em Branco");
            ok = 0;
        }
        if(ok){
            if($("#slcAbrangencia").val() != ""){
                var toadd = $('#slcEquipamento option:selected').text();
                var existe = 0;
    
                $("#divListaEquipamento tr>td:nth-child(4)").each(function(index){
                    if( $(this).text() == toadd)
                        existe = 1;
                  });
    
                if(existe != 1){
    
                    var uf = $('#slcUF option:selected').text();
                    var loc = $('#slcLocalidade option:selected').text();
                    var est = $('#slcEstacao option:selected').text();
                    if($("#slcEquipamento").val() > 0){
                        $("#hdnEquipamento").val($("#slcEquipamento").val()+"||"+$('#slcEquipamento option:selected').text());
                    }else{
                        var equip = $('#txtEquipamento').val().substr(0,15);
                        $("#hdnEquipamento").val(equip);
                    }
                    var tempLoc = loc.split("-");
                    var tempEst = est.split("-");
                    $("#hdnUF").val(uf.substr(0,2));
                    $("#hdnLocalidade").val(tempLoc[0]);
                    $("#hdnEstacao").val(tempEst[0]);
                    $.post("/aplicacao/jm/index.php/janela/addequipamento", $("#frmNovaJanela").serialize(),
                               function(data){
                                    if(data[0] != null){
                                        $("#listaEquipamentos > tbody:last").append("<tr><td>"+data[1]+"</td><td>"+data[3]+"</td><td>"+data[5]+"</td><td>"+data[7]+"</td><td>"+data[8]+"</td><td><input class='bot1' type='button' value='X'></td></tr>");
                                        var total = parseInt($("#totalCliente").val()) + parseInt(data[8]);
                                        $("#totalCliente").val(total);
                                    }else alert("Problema ao gravar equipamento.")
                                 }, "json");                
                }else{
                    alert('O Equipamento '+toadd+' já está na lista.');
                }
            }else{
                alert ("Favor Selecionar a Abrangencia.");
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.