Last active
April 11, 2021 09:12
-
-
Save tcomaj/527b00fe927643f524353541c43e4133 to your computer and use it in GitHub Desktop.
jQuery like shorthand for qs, qsa + add Array methods to NodeList prototype
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
NodeList.prototype.__proto__ = Array.prototype; | |
// Use any array methods on NodeLists | |
$$('.cards').map(card => card.textContent); // ['card 1', 'card 2'] |
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
// Create global variables | |
window.$ = document.querySelector.bind(document); | |
window.$$ = document.querySelectorAll.bind(document); | |
$('.card'); // <div class="card"></div> | |
$$('.card'); // [<div class="card"></div>, <div class="card"></div>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment