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

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)

Retry later