DEV Community

Cover image for DOM Element ID as Global Variable
Vuelancer
Vuelancer

Posted on • Edited on

1 1 1 1 1

DOM Element ID as Global Variable

Hey Developers,

I have created a detailed explanation video about how global variables are created when the dom elements are having id attribute.

Introduction

  • Javascript is a client and server side programming language which basically makes the webpages as dynamic.
  • In Javascript, HTML DOM elements can be accessed by an object called document.
  • Javascript variables will be created to access the dom elements by their id, tagname, classname, css selectors by using the respective methods inside the document object, which is accessible in Javascript.
  • Instead of creating the variables, the html element can also be accessed if it has id attribute.

Explanation

Final thoughts

  • The advantage of this technique is If you are having more number of dom elements, then you need to create as much as variables. But, you can directly access the dom elements by without creating any external variables.
  • The convention for accessing dom elements is only by creating variables. Alt Text
  • One more factor is you can rename the variable and create any number of variable for the single dom element with the different variable name.

    • Thank You.

Support Me

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay