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

Karthik Malla
  • 5,570
  • 12
  • 46
  • 89

2 Answers2

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.

Sam1604
  • 1,459
  • 2
  • 16
  • 26
  • 1
    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`. – Jukka K. Korpela Aug 22 '14 at 07:10
  • http://stackoverflow.com/questions/5468350/javascript-not-running-on-jsfiddle-net refer this and also check the Demo in my answer – Sam1604 Aug 22 '14 at 07:32
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

japtain.cack
  • 131
  • 11