jqueryの$をバニラjsで使う
バニラjsでいちいちdocument.querySelector
とか、document.getElementById
とか書くのは面倒なので$
で済ましたい。
コード
es6なら一行で書ける
let $ = (selector) => document.querySelector(selector)
bindメソッドを使う方法
let $ = document.querySelector.bind(document)
例
See the Pen jquery$ by kodamaworld (@kodamaworld) on CodePen.
See the Pen jquery$ by kodama (@kodamaparadise) on CodePen.