Skip to content

Instantly share code, notes, and snippets.

@javascripto
Created May 12, 2020 15:58
Show Gist options
  • Select an option

  • Save javascripto/ee1d3d950b565a59f94b0df97054f947 to your computer and use it in GitHub Desktop.

Select an option

Save javascripto/ee1d3d950b565a59f94b0df97054f947 to your computer and use it in GitHub Desktop.
function $(selector) {
const el = document.querySelector(selector);
return ({
html: () => el,
hide: () => el.hidden = true,
show: () => el.hidden = false,
on: (event, callback) => el.addEventListener(event, callback),
attr: (name, value) => value ? el.setAttribute(name, value) : el.getAttribute(name),
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment