Commits

Keiji Matsuzaki committed 2a01591

add .hgignore and question_2/sample_1

  • Participants

Comments (0)

Files changed (3)

+syntax = glob
+.DS_Store

question_2/sample_1/index.html

+<html>
+  <head>
+    <meta charset="UTF-8">
+    <title>create element and append child</title>
+  </head>
+  <body>
+    <div>
+      <h1>create element and append child</h1>
+      <button id="insert-element">insert 100 element</button>
+    </div>
+    <hr/>
+    <div id="target">
+    </div>
+    <script type="text/javascript" src="main.js"></script>
+
+  </body>
+</html>

question_2/sample_1/main.js

+(function(window){
+  var MyApp = {
+    init: function(){
+      $.target = document.getElementById("target");
+      $.button = document.getElementById("insert-element");
+      $.button.addEventListener("click", $.insert, false);
+    },
+    cleanup: function(){
+      if ($.target.childNodes != null){
+        while($.target.firstChild){
+          $.target.removeChild($.target.firstChild);
+        }
+      }
+    },
+    create: function(no){
+      var p = document.createElement("p");
+      p.appendChild(document.createTextNode("Element: " + no));
+      return p;
+    },
+    insert: function(){
+      $.cleanup();
+      var start = (new Date).getTime();
+      for(var i = 1; i <= 100; i++){
+        $.target.appendChild($.create(i));
+      }
+      var finish = (new Date).getTime();
+      console.log(finish - start);
+    }
+  };
+  window.MyApp = window.$ = MyApp;
+})(window);
+
+$.init();