DEV Community

Cover image for Selecting an Element
GiandoDev
GiandoDev

Posted on

Selecting an Element

In JavaScript if we want to select an element inside our DOM and for example we want to change the color, we can do it this way
Alt Text
The document object contains the method querySelector that allows us to point to the element that we want to
Alt Text
As in the example above we pass inside querySelector("ID / CLASS / TAG / and ATTRIBUTE but just [INSIDE SQUARE BRACKETS ]")
No matter how many elements match our call; will always be selected the first starting from the root element and down to the last element
Alt Text
There are other ways to select multiple items at once but we'll talk about it in another moment (querySelectorAll).
Alt Text
In the example above we see that every element has the querySelector method too so we may select an element children through its father without going through the root element and going down the whole tree.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️