Last active
March 9, 2019 21:27
-
-
Save brimelow/5605832 to your computer and use it in GitHub Desktop.
Native equivalents to jQuery selectors
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
//----Get all divs----------------- | |
// jQuery | |
$("div") | |
// native equivalent | |
document.getElementsByTagName("div") | |
//----Get all by CSS class--------- | |
// jQuery | |
$(".my-class") | |
// native equivalent | |
document.querySelectorAll(".my-class") | |
// or the 100% faster alternative | |
document.getElementsByClassName("my-class") | |
//----Get by CSS selector---------- | |
// jQuery | |
$(".my-class li:first-child") | |
// native equivalent | |
document.querySelectorAll(".my-class li:first-child") | |
//----Get first by CSS selector---- | |
// jQuery | |
$(".my-class").get(0) | |
// native equivalent | |
document.querySelector(".my-class") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment