Advertisement
nzisaacnz

html javascript test

Sep 6th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.29 KB | None | 0 0
  1. <script>
  2.  
  3.   function Arguments(data){
  4.    
  5.     function recurse(left,right){
  6.       for(var a in right){
  7.         if(right[a] instanceof Object){
  8.           left[a] = {};recurse(left[a],right[a]);
  9.         }
  10.         else left[a] = right[a];
  11.       }
  12.     }
  13.    
  14.    
  15.     this.data = data;
  16.     this.attach = function(elem){
  17.       recurse(elem,this.data);
  18.     }
  19.   }
  20.   function A(data){
  21.     return new Arguments(data);
  22.   }
  23.  
  24.  
  25.  
  26.   function node(name,first,data){
  27.     var elem = document.createElement(name);
  28.    
  29.     var s = 0;
  30.     if(first instanceof Arguments){
  31.       first.attach(elem);
  32.       s = 1;
  33.     }
  34.     for(var a=s; a<data.length; a++){
  35.      elem.appendChild(data[a]);
  36.    }
  37.    return elem;
  38.  }
  39.  
  40.  
  41.  
  42.  function html(first){return node("html",first,arguments);}
  43.  function head(first){return node("head",first,arguments);}
  44.  function body(first){return node("body",first,arguments);}
  45.  function div(first){return node("div",first,arguments);}
  46.  function span(first){return node("span",first,arguments);}
  47.  
  48.  
  49.  (function(){
  50.  
  51.    
  52.    var a = html(
  53.      head(),
  54.      body(
  55.         span(A({innerText:"U wot m8",style:{fontWeight:"bold"}}))
  56.      )
  57.    );
  58.  
  59.    document.open();
  60.    document.write(a.outerHTML);
  61.    document.close();
  62.  })();
  63. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement