Javascript Clonenode() - get element by id?

sqlmole picture sqlmole · Jul 28, 2011 · Viewed 7.8k times · Source

I am fiddling with this javascript code here

http://jsfiddle.net/7Sd4W/4/

I am trying to get it to clone a select element with ID = "sel0"

Then when It clones it I want it to create the same select element but with "sel+i" , i increments meaning everytime its cloned

The ids would be sel0,sel1,sel2,sel3,sel4 etc..

I tried changing

document.getelementsbyID()

or

document.getelementsbyname()

However it does not seem to work

Thanks

Answer

shabunc picture shabunc · Jul 28, 2011
var copy = orig.cloneNode(true);
copy.setAttribute("id", modify(orig.getAttribute("id")));
document.body.appendChild(el)