deleteRow Does not completely delete the table row

0

Here is my javascript function that should permanently delete a line:

function deletaItemExtra(item){

            var x = document.getElementById(item);

            x.deleteCell(1);

            x.deleteCell(0);

            document.getElementById(item).deleteRow;

            if(document.getElementById(item) != null){

                alert('Ainda é encontrado no sistema'); 

            }else{

                alert('Foi totalmente deletado do sistema'); 

            }

        }

The problem is that when I check the lines, which should have been deleted, it is still in the table. For this reason I put this check at the end. The table is also generated dynamically. Here is the code:

var itemExtra   = itemExtra.split("|");
                var idExiste = false;
                var id = 0;
                while(idExiste == false){
                    id  = Math.floor((Math.random() * 10000) + 1) + '_' + itemExtra[0].replace(' ', '');
                    if(document.getElementById(id) == null){
                        idExiste = true;
                    }
                }
                var table       = document.getElementById(tabela);
                var row         = table.insertRow(0);
                row.id          = id;
                var cell1       = row.insertCell(0);
                var cell2       = row.insertCell(1);
                cell1.innerHTML = itemExtra[1];
                var deletaExtra = document.createElement("INPUT");
                deletaExtra.setAttribute("type", "button");

                deletaExtra.addEventListener("click", function(){
                    deletaItemExtra(id.replace(" ",""));
                });

                deletaExtra.setAttribute("value", 'X');
                cell2.appendChild(deletaExtra);

I searched and in some places said that it could be on account of the daughters, so I'm deleting the two. Any issues?

    
asked by anonymous 25.07.2017 / 22:53

1 answer

2

You are not calling the function. This:

document.getElementById(item).deleteRow

should be:

document.getElementById(item).deleteRow(0);

or simply:

x.deleteRow(0);

I am passing zero, which represents the first row of the table because I do not know which row you want to delete. But you need to pass the index of the line to be removed.

    
25.07.2017 / 22:57