开发者

Javascript Clonenode() - get element by id?

开发者 https://www.devze.com 2023-03-23 18:06 出处:网络
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\"

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


var copy = orig.cloneNode(true);
copy.setAttribute("id", modify(orig.getAttribute("id")));
document.body.appendChild(el)


getElementsByTagName works. You can also assign a unique ID to the node before appending it (duplicate IDs can cause all kinds of issues):

See http://jsfiddle.net/7Sd4W/9/

0

精彩评论

暂无评论...
验证码 换一张
取 消