Skip to content

Instantly share code, notes, and snippets.

@jadudm
Created May 28, 2020 13:01
Show Gist options
  • Save jadudm/14222424f3f90abf85255a6b90c57fcb to your computer and use it in GitHub Desktop.
Save jadudm/14222424f3f90abf85255a6b90c57fcb to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Replacing JQuery?</title>
</head>
<body>
<script>
let MiniQuery = class {
constructor (queryString) {
this.queryString = queryString;
// In JQuery...
// $(".thing") selects all instances
this.elements = document.querySelectorAll(queryString);
console.log(this.elements)
}
hide () {
console.log("hide");
this.elements.forEach(e => { e.style.display = "none" });
return this;
}
}
function $ (selector) {
q = new MiniQuery(selector);
return q;
}
</script>
<div id="one" class="a">One</div>
<div id="two" class="a">Two</div>
<div id="three" class="b">Three</div>
<div id="four" class="b">Four</div>
<div id="five" class="c">Five</div>
<script>
$(".a").hide();
$("#five").hide();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment