Last active
June 27, 2022 10:00
-
-
Save stayradiated/5617498 to your computer and use it in GitHub Desktop.
Using native methods instead of jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class $ | |
constructor: (query) -> | |
return document.querySelector(query) | |
@find: (parent, query) -> | |
parent.querySelector(query) | |
@findAll: (parent, query) -> | |
parent.querySelectorAll(query) | |
@create: (tag) -> | |
document.createElement(tag) | |
@append: (el) -> | |
document.body.appendChild(el) | |
@prepend: (el) -> | |
document.body.insertBefore(el, document.body.firstChild) | |
@class: (className) -> | |
document.getElementsByClassName(className) | |
@all: (query) -> | |
document.querySelectorAll(query) | |
@addClass: (el, className) -> | |
el.classList.add(className) | |
@removeClass: (el, className) -> | |
el.classList.remove(className) | |
@toggleClass: (el, className, value) -> | |
el.classList.toggle(className, value) | |
@hasClass: (el, className) -> | |
el.classList.contains(className) | |
@css: (el, prop, val) -> | |
el.style[prop] = val | |
module.exports = $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment