How can I alias the function "document.getElementById" I've seen it done using $
Thanks
The new features introduced in ES6 let us improve on Chris Lloyd's answer, simplifying:
function $(id) { return document.getElementById(id); };
to:
const $ = id=> document.getElementById(id);
var $ = document.getElementById.bind( document );
Possibly the easiest/shortest way:
function $(id) { return document.getElementById(id); };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With