saginadir
1/13/2017 - 11:57 AM

miniJquery.js

const wrap = (el) => ({
  css: (attribute, value) => {
    el.style[attribute] = value;
    return wrap(el);
  },
  hide: () => {
    return wrap(el).css('display', 'none');
  },
  show: () => {
    return wrap(el).css('display', 'block');
  },
  html: (newHtml) => {
    if(newHtml) {
      el.innerHTML = newHtml;
      return wrap(el);
    } else {
      return el.innerHTML;
    }
  }
})

const $ = (el) => wrap(document.querySelector(el))

const $example = $('.example');

$example
  .css('width', '100px')
  .css('height', '100px')
  .css('backgroundColor', 'firebrick')
  .hide()
  .show()
  .html('Hello World');