Skip to content

03. Get Elements by Class Name (dgCN.js)

Pimp Trizkit edited this page Mar 6, 2018 · 1 revision
<< Previous        Back to Table of Contents        Next >>

    "You Gotta Have Class." - PT

This is just an alias function to shorten other JS code.

"dgCN" alias for "document.getElementsByClassName".

This will search inside document for elements that have a className equal to the string specified. And then return a HTML Collection of those elements.

Code:

const dgCN=(c)=>document.getElementsByClassName(c);

Usage:

let hc = dgCN("myClassName");

Return:

A HTML Collection of HTML Elements, from inside document, that have className equal to the parameter specified. NOTE: If no such elements exists, the collection will be empty.

Params:

dgCN(c)

c = < ClassName String > * REQUIRED

  • A string to search in document for elements of the same className.
  • This function uses document.getElementsByClassName(), and is just an alias.