0

I have a table, and each row is added through JavaScript. I create these rows so that when they're clicked another cell will be created beneath them where I can display additional information. Now I want to be able to destroy the row I just created when the user clicks a button etc. So essentially, I need to be able to have the row I created have an onclick attribute, but it doesn't seem to work... I've tried everything I can think of so any help would be awesome!

 var table = document.getElementById("main_table");
var row = table.insertRow(1);
row.id = count;
row.onclick = function () 
{

var id = this.id;


var target = document.getElementById(id);
var newElement = document.createElement('tr');
newElement.style.height = "500px";
newElement.id = id + "" + id;
//newElement.innerHTML = text;




target.parentNode.insertBefore(newElement, target.nextSibling );


//var newRow = document.createElement("tr");
//var list = document.getElementById(id);
//list.insertAfter(newRow,list);


var newRow = table.insertRow(newID);
}

1 Answer 1

1

I have tried to mimic your problem with below fiddle.

http://jsfiddle.net/kr7ttdhq/12/

newElement.onclick = createClickableCells;
del.onclick = delCell;

The above code shows the snippet from the fiddle

During the onclick event of the cell. New cells are created which in turn have the same onclick events as the first cell. Moreover, a 'close' text cell is inserted by which you can delete the entire row.

Hope this helps

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

Comments

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.