Skip to content

Instantly share code, notes, and snippets.

@saginadir
Last active January 13, 2017 11:59
Show Gist options
  • Save saginadir/050ac7efec643884fad7e6a33e94e274 to your computer and use it in GitHub Desktop.
Save saginadir/050ac7efec643884fad7e6a33e94e274 to your computer and use it in GitHub Desktop.
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment