DEV Community

0 seconds of 3 minutes, 48 secondsVolume 90%
Press shift question mark to access a list of keyboard shortcuts
00:00
00:00
03:48
 
Vuelancer
Vuelancer

Posted on

5 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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

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