DEV Community

Vijay SRJ
Vijay SRJ

Posted on

Tips to save time typing document.getElementById() and document.createElement() in javascript

You can save time typing document.getElementById(elementId) and document.createElement(elementType) by following a simple trick:

  • Create a function which executes either of the above lines of code
  • Assign the function to a variable
  • Use that variable instead of typing the redundant code

Here is a demo with screenshots:

https://fullstackdeveloper.guru/2021/02/19/how-to-save-time-typing-document-getelementbyid-value-and-document-createelement-in-javascript/

Top comments (0)