---
title: "Comment by Jordan Brennan on \"Dom Manipulation In Javascript\" | Hashnode"
description: "Nice summary! I recently learned something new that you can do to avoid. a bunch of document.getElementById() calls. You can create a tiny Proxy and get a singl"
url: "https://hashnode.com/posts/dom-manipulation-in-javascript/645b83b8f559ad8d059b600a/comment/6465b110eb43c7e4ebcfdd51"
---

[Discussion](https://hashnode.com/posts/dom-manipulation-in-javascript/645b83b8f559ad8d059b600a)

Comment [Dom Manipulation In Javascript](https://hashnode.com/posts/dom-manipulation-in-javascript/645b83b8f559ad8d059b600a)

[Jordan Brennan](https://hashnode.com/@jfbrennan)

[May 18, 2023](https://hashnode.com/posts/dom-manipulation-in-javascript/645b83b8f559ad8d059b600a/comment/6465b110eb43c7e4ebcfdd51)

Nice summary! I recently learned something new that you can do to avoid. a bunch of `document.getElementById()` calls. You can create a tiny Proxy and get a single object that effectively gives you direct access to every element with an id, like this:

```
// Given this HTML...
<h1 id="welcomeMessage" hidden>Welcome!</h1>

// Elements Proxy (make this a global, a module, or just add it to the top of your script)
const elements = new Proxy({}, {
  get(target, prop) {
    return document.getElementById(prop);
  }
});

elements.welcomeMessage.hidden = false;
```
