← Snippets

Quicky Element Selector

const qs = (s, o = document) => o.querySelector(s)
const qsa = (s, o = document) => o.querySelectorAll(s)

// Returns the first element
qs('div') // Instead of document.querySelector('div');

// Returns the first element within element
qs('div', elem) // Instead of elem.querySelector('div');

// Returns all elements
qsa('div') // Instead of document.querySelectorAll('div');

// Returns all elements within the element
qsa('div', elem) // Instead of elem.querySelector('div');
Discuss on Twitter