Skip to content

05. Get Element by ID (dgI.js)

Pimp Trizkit edited this page Mar 7, 2018 · 2 revisions
<< Previous        Back to Table of Contents        Next >>

    "21 or over." - PT

This is just an alias function to shorten other JS code. I just reinvented the exact same wheel here.

"dgI" alias for "document.getElementByID".

Searches inside document for a HTML Element with id equal to the provided string, and returns it. NOTE: The id attribute is meant to be unique amongst all elements in the DOM that use it.

Code:

const dgI=(i)=>document.getElementById(i)||false;

Usage:

let e = dgI("myID");

Return:

A HTML Element, from inside document, that has id equal to the parameter specified. NOTE: If no such element exists, false will be returned.

Params:

dgI(i)

i = < ID String > * REQUIRED

  • A string to search in document for the first occurance of an element with the same id.
  • This function uses document.getElementByID(), and is just an alias, except that it converts the null to a false when no element is found.

Clone this wiki locally