Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 11th, 2012  |  syntax: None  |  size: 2.16 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <html>
  2.         <head>
  3.                 <title>CSS to JavaScript</title>
  4.                 <script type="text/javascript">
  5.                 </script>
  6.                 <style type="text/css">
  7.                        
  8.                 </style>
  9.         </head>
  10.         <body>
  11.                
  12.                 <script type="text/javascript">
  13.                         (function() {
  14.                                 var d = document,
  15.                                         DOMParentElement = function(e, id) {
  16.                                                 this.element = d.body.appendChild(d.createElement(e));
  17.                                                 this.element.id = id;
  18.                                                 this.accessElement = function() {
  19.                                                         return this.element;
  20.                                                 };
  21.                                         };
  22.                                 Object.prototype.append = function(e, id) {
  23.                                                 var el = this.appendChild(d.createElement(e));
  24.                                                 el.id = id;
  25.                                                 };
  26.                                 var respectiveStyle = ["background-color", "color", "font-family", "font-size", "position", "left", "right", "top", "bottom", "margin-left", "margin-right", "margin-top", "margin-bottom", "width", "height"],
  27.  
  28.                                         mainHeader = new DOMParentElement("DIV", "main_header");
  29.                                 mainHeader.accessElement().append("DIV", "container");
  30.                                
  31.                                 var container = document.getElementById("container");
  32.                                 container.append("SPAN", "text-first-half");
  33.                                 container.append("SPAN", "text-second-half");
  34.                                
  35.                                 var textFH = document.getElementById("text-first-half"),
  36.                                         textSH = document.getElementById("text-second-half");
  37.                                
  38.                                 textFH.textContent = "Co";
  39.                                 textSH.textContent = "ol";
  40.                                
  41.                                 var allHTMLElements = document.getElementsByTagName("*");
  42.                                 for (var i = 0; i < allHTMLElements.length; i++) {
  43.                                         allHTMLElements[i].style.padding = 0;
  44.                                         allHTMLElements[i].style.margin = 0;
  45.                                 }
  46.                                
  47.                                 for (var i = 0; i < respectiveStyle.length; i++) {
  48.                                
  49.                                         mainHeader.accessElement().style[respectiveStyle[i]] = ["#666666", false, "Tahoma"][i];
  50.                                         container.style[respectiveStyle[i]] = ["#9E9E9E", false, false, "100px", false, false, false, false, false, "1px", "1px", "1px", false, "50%", "10em"][i];
  51.                                         textFH.style[respectiveStyle[i]] = [false, "#ffffff", mainHeader.accessElement().style.fontFamily, false, "absolute", "515px", false, false, "350px"][i];
  52.                                         textSH.style[respectiveStyle[i]] = [false, "#000000", mainHeader.accessElement().style.fontFamily, false, "absolute", "635px", false, false, "350px"][i];
  53.                                 }
  54.                         })();
  55.                 </script>
  56.         </body>
  57. </html>