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)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

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

Okay