Javascript DOM - add form element to newly created appendChild? -


I have two functions to add and delete table rows that have a form input element. They both work fine, but I have a problem that I only have to show an extract button input on the table rows that were created later. My two functions are as follows:

  function addRow (table_id) {var clone; Var rows = document. GetElementById (table_id) .getElementsByTagName ('tr'); Var index = rows.length; Var tbo = document.getElementById (table_id) .getElementsByTagName ('Toby') [0]; Clone = rows [index-1] .cloneNode (true); Tbo.appendChild (clone); } Function delRow (table_id, button) {var row = button.parentNode.parentNode; Var tbo = document.getElementById (table_id) .getElementsByTagName ('Toby') [0]; Tbo.removeChild (line); }  

and has html content:

   Upload file & lt; Input type = "file" name = "upload file [onchange =" addRow ('mytab') "/> & lt; input name =" del_row "type =" button "value =" remove row "onclick =" delRow ('Mytab', this) "/> gt;  & lt; / tr & gt; & lt; / table & gt; & lt; / form & gt;  

I do not mean a javascript expert - more of a newbie - so I'm struggling to come up with a solution.

Class = " Post-text "itemprop =" text ">

I agree that you can prevent the button being deleted in the first line Trying to escape, but now there is a need for it because you feel that it has to be obtained in later lines, you should be in the line that you want to clone. If, instead, you complete the addRow method By the way, you can avoid clones and your original line will not make any difference. AddRow (table_id) {var table = document.getElementById (table_id); Var line = table.insertRow (table.rows.length); Var cell = Row.insertCell (0); Var template = table.oroz [0]. Seals [0]. WinnerHTML; Cell.innerHTML = Template + '& lt; Input type = "button" value = "delete row" '+' onclick = "delRow (\ '' + table_ id + '\', this); "/ / Gt; '}

It still uses the first row as a template, but you can remove that button from it because it is added by adding existing text


Comments