Skip to content

Instantly share code, notes, and snippets.

@goiblas
Created June 8, 2022 06:46
Show Gist options
  • Save goiblas/01fa094ea6c090bda8ba0fcd356cfa82 to your computer and use it in GitHub Desktop.
Save goiblas/01fa094ea6c090bda8ba0fcd356cfa82 to your computer and use it in GitHub Desktop.
function $(selector) {
const element = typeof selector === 'string'
? document.querySelector(selector)
: selector
return {
addClass(className) {
element.classList.add(className)
return this
},
removeClass(className) {
element.classList.remove(className)
return this
},
attr(name, value) {
element.setAttribute(name, value)
return this
},
on(event, callback) {
element.addEventListener(event, callback)
return this
}
}
}
$(".button").on("click", function() {
$(this).addClass("active").attr("disabled", true)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment