A little bit of plain JavaScript can do a lot
When starting to learn&#x2F;write JS, I found a few of these basic name-shortening functions from HN&#x27;s own JS very useful, and well-named:<p><pre><code>    function $(id) { return document.getElementById(id); }
    function byClass (el, cl) { return el ? el.getElementsByClassName(cl) : [] }
    function byTag (el, tg) { return el ? el.getElementsByTagName(tg) : [] }
    function allof (cl) { return byClass(document, cl) }
    function hasClass (el, cl) { var a = el.className.split(&#x27; &#x27;); return afind(cl, a) }
    function addClass (el, cl) { if (el) { var a = el.className.split(&#x27; &#x27;); if (!afind(cl, a)) { a.unshift(cl); el.className = a.join(&#x27; &#x27;)}} }
    function remClass (el, cl) { if (el) { var a = el.className.split(&#x27; &#x27;); arem(a, cl); el.className = a.join(&#x27; &#x27;) } }
    function html (el) { return el ? el.innerHTML : null; }
    function attr (el, name) { return el.getAttribute(name) }
    function tonum (x) { var n = parseFloat(x); return isNaN(n) ? null : n }
    function remEl (el) { el.parentNode.removeChild(el) }
    function posf (f, a) { for (var i=0; i &lt; a.length; i++) { if (f(a[i])) return i; } return -1; }
    function apos (x, a) { return (typeof x == &#x27;function&#x27;) ? posf(x,a) : Array.prototype.indexOf.call(a,x) }
    function afind (x, a) { var i = apos(x, a); return (i &gt;= 0) ? a[i] : null; }
    function acut (a, m, n) { return Array.prototype.slice.call(a, m, n) }
    function aeach (fn, a) { return Array.prototype.forEach.call(a, fn) }
    function arem (a, x) { var i = apos(x, a); if (i &gt;= 0) { a.splice(i, 1); } return a; }
    function alast (a) { return a[a.length - 1] }
    function vis(el, on) { if (el) { (on ? remClass : addClass)(el, &#x27;nosee&#x27;) } }
    function noshow (el) { addClass(el, &#x27;noshow&#x27;) }
    function elShow (el) { remClass(el, &#x27;noshow&#x27;) }
    function ind (el) { return (byTag(el, &#x27;img&#x27;)[0] || {}).width }
</code></pre>
<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;hn.js" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;hn.js</a>