Delete the correct cell

wxdqz

New Member
This is a little unusual, and Iam not able to figure it out....

Suppose I have a table with one row and 2 cells. Such as -
1. Create a dynamic row, id=row1
2. Insert a cell dynamically, id=cell1
3. Insert a cell before cell1, id=cell2 //using insertBefore()

hence the table looks like -
cell2 cell1 --> in row1

when I use the following code to delete cell, id=cell1

//cName = cell1 ---> creates object of id cell1
var cellToDelete = document.getElementById(cName);

//Creates an object of Row1
var cellOfRow = document.getElementById
(cellToDelete.parentNode.id);

//delete cell , id=cell1
cellOfRow.deleteCell(cellToDelete.id);

whereas the table looks like
cell1 --> in row1 (cell2 gets deleted)

and i want it to look like
cell2 --> in row1

Anyone ?
 
Back
Top