Referencing and changing attributes of HTML button inside container

as4uif

New Member
Below is the HTML code I am playing with. All it does is create an element with two buttons: "Element1" (TitleButton) and "Add". By clicking on "Add" the element is cloned and assigned id="element 2". What I am not able to do is assign value "Element2" for the TitleButton of the cloned element. How can I do it, preferably inside addNode() function? If it is not possible then what are other ways? Thanks\[code\]<HTML><HEAD><TITLE>Dynamically add Textbox, Radio, Button in html Form using JavaScript</TITLE> <SCRIPT language="javascript"> function addNode(element) { var adding_element = element.parentNode; var added_element=adding_element.cloneNode(true); added_element.setAttribute("id","element 2"); var cont = adding_element.parentNode; cont.appendChild(added_element); }</SCRIPT></HEAD><BODY><FORM> <div name="container" id="container"> <div name="element 1" id="element 1"> <input type="button" value= "http://stackoverflow.com/questions/15859599/element1"; name="TitleButton" /> <input type="button" value="http://stackoverflow.com/questions/15859599/Add" name="add[]" onclick="addNode(this)" /> </div> </div></FORM></BODY></HTML>\[/code\]
 
Back
Top