I'm cloning some table rows and would like to increment the IDs of its child nodes, I've tried doing this by:
var rowID = document.getElementById('RowTbl').rows.length / 2;
var NameRowCopy= document.getElementById('NameRow' + rowID).cloneNode(true);
NameRowCopy.getElementByID('txtName1').setAttribute('id', 'txtName' + (rowID + 1));
So I get the latest set of rows (2 are created each time), and divide by 2 to get the current row ID. I then store the l开发者_运维知识库atest table row into a var, ready for cloning, and attempt to set the child node IDs from there.
Unfortunately, Firebug errors out silently so I'm left clueless as to what's going on. What is going on???
There's no such thing as "errors out silently" if you're running in Firebug - it'll either error (verbosely), or do the right thing (silently).
In this case, you don't appear to be adding the cloned node back into the DOM.
Also, getElementById()
is a document
method, you can't use it on any arbitrary HTML element.
You should be getting an error when you attempt to invoke element.getElementById()
telling you that there's no such method.
精彩评论