Advertisement
Guest User

StackOverflow question 10038801

a guest
Apr 5th, 2012
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.27 KB | None | 0 0
  1. <html>
  2. <body>
  3.    
  4.     <fieldset>
  5.         <legend>Legend</legend>
  6.         <div id="sections"></div>
  7.         <a id="add-new-section" href="#">add</a><br />
  8.     </fieldset>
  9.  
  10.     <script>
  11.  
  12.     var newSection = function() {
  13.  
  14.         var section = document.createElement('div');
  15.  
  16.         var text1 = document.createElement('input');
  17.         text1.type = 'text';
  18.         text1.name = 'text1';
  19.         text1.value = 'Text1';
  20.         section.appendChild(text1);
  21.  
  22.         var space1 = document.createElement('span');
  23.         space1.innerHTML = ' ';
  24.         section.appendChild(space1);
  25.  
  26.         var text2 = document.createElement('input');
  27.         text2.type = 'text';
  28.         text2.name = 'text2';
  29.         text2.value = 'Text2';
  30.         text2.size = '40';
  31.         section.appendChild(text2);
  32.  
  33.         var space2 = document.createElement('span');
  34.         space2.innerHTML = ' ';
  35.         section.appendChild(space2);
  36.         section.appendChild(space2);
  37.  
  38.         var close = document.createElement('input');
  39.         close.type = 'button';
  40.         close.value = 'x';
  41.         close.style.width = '26px';
  42.         close.onclick = function() {
  43.             var parent = this.parentNode;
  44.             parent.parentNode.removeChild(parent);
  45.         };
  46.         section.appendChild(close);
  47.  
  48.         document.getElementById('sections').appendChild(section);
  49.    
  50.     };
  51.  
  52.     document.getElementById('add-new-section').onclick = newSection;
  53.  
  54.     newSection();
  55.  
  56.     </script>
  57.  
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement