Comment

Comment by mg

Browsers have become so nice to work with, that these days, I get away with just the following two lines of code to simplify DOM manipulation:

    dqs  = document.querySelector.bind(document);
    dqsA = document.querySelectorAll.bind(document);
So instead of

    country = document.querySelector('#country');
    cities  = document.querySelectorAll('.city');
I can write

    country = dqs('#country');
    cities  = dqsA('.city');
For everything else, I am fine with just using the native browser functions.

I usually import the two functions from a module like this:

import { dqs, dqsA } from '/lib/js/dqs.js';

This is the module:

https://github.com/no-gravity/dqs.js

parent mg 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton