table.js

HTML Table manage easily

by Ukjin Yang

JavaScript

(function(un){
    'use strict';
    var proto = {
        
    };
    var table = {
        get: function(table){
            var isStr;
            if(!table && ((isStr = (typeof(table) == 'string' || table instanceof String)) || table.nodeName != 'TABLE')){return null;}
            
            if(isStr){
                if(document.querySelector){
                    table = document.querySelector(table);
                }else{
                    table = document.getElementById(table);
                }
            }
            
            if(table){
                for(var prop in proto){
                    table[prop] = proto[prop];
                }
            }
            
            return table;
        },create: function(){
            return table.get(document.createElement('table'));
        }
    };
    
    window.Table = table;
})();

var table = document.body.appendChild(Table.create());