Below is an 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

<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= "element1"; name="TitleButton" />
      <input type="button" value="Add" name="add[]" onclick="addNode(this)" />
    </div>
  </div>
</FORM>
</BODY>
</HTML>
share

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.