3

I am trying to delete the TR from the table using JavaScript and I don't know for some reasons when I click on delete button its not deleting the complete TR instead its just deleting the img file.

function remove(rowid)  
{   
    var row = document.getElementById(rowid);
    var table = row.parentNode;
    while ( table && table.tagName != 'TABLE' )
        table = table.parentNode;
    if ( !table )
        return;
    table.deleteRow(row.rowIndex);
}

Please check the JS Fiddle for reference http://jsfiddle.net/h09wsrox/

Thanks

0

2 Answers 2

4
function removee(rowid)  
{   
    var row1 = document.getElementById(rowid);
    var table1 = row1.parentNode;
    while ( table1.tagName != 'TABLE' )
        table1 = table1.parentNode;
    if ( !table1 )
        return;
    table1.deleteRow(row1.rowIndex);

}

I have updated your js function name to remove to removee and also some small changes in it.

Here is a DEMO

JavaScript in separate block DEMO

I hope it helps you.

Sign up to request clarification or add additional context in comments.

2 Comments

The problem is indeed with the identifier remove, which is treated as predefined for some reason. Replacing it by any suitable identifier fixes the problem. I would rather use a more natural identifier like removeRow.
stackoverflow.com/questions/5468350/… refer this and also check the Demo in my answer
1

I had to do a similar function but to a whole class. It should be similar though. Not sure of your requirements, but I used JQuery to accomplish this.

function remove(rowid){
    $("#" + rowid).remove();
}

Source

3 Comments

Try this one. Note I had to change the settings on the left. jsfiddle.net/h09wsrox/23
You could also make it have animations like this: jsfiddle.net/h09wsrox/24
Just remember, when using JQuery, you should use the $(document).ready(function(){ yourjqueryhere }); learn.jquery.com/using-jquery-core/document-ready

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.