Skip to content

Instantly share code, notes, and snippets.

@tcomaj
Last active April 11, 2021 09:12
Show Gist options
  • Save tcomaj/527b00fe927643f524353541c43e4133 to your computer and use it in GitHub Desktop.
Save tcomaj/527b00fe927643f524353541c43e4133 to your computer and use it in GitHub Desktop.
jQuery like shorthand for qs, qsa + add Array methods to NodeList prototype
NodeList.prototype.__proto__ = Array.prototype;
// Use any array methods on NodeLists
$$('.cards').map(card => card.textContent); // ['card 1', 'card 2']
// 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