-
Notifications
You must be signed in to change notification settings - Fork 24
04. Get First Element by Class Name (dgCNz.js)
Pimp Trizkit edited this page Mar 7, 2018
·
3 revisions
| << Previous | Back to Table of Contents | Next >> |
"I always roll first class... i think." - PT
This is just an alias function to shorten other JS code.
"dgCNz" alias for "document.getElementsByClassName (zero index)".
This will search inside document for the first element that has a className equal to the string specified. And then return that element or undefined.
const dgCNz=(c)=>document.getElementsByClassName(c)[0]||false;let e = dgCNz("myClassName");The first HTML Element, from inside document, that has className equal to the parameter specified. NOTE: If no such element exists, false will be returned.
dgCN(c)
c = < ClassName String > * REQUIRED
- A string to search in
documentfor the first occurance of an element with the sameclassName. - This function uses
document.getElementsByClassName(), and is just an alias, except that it converts theundefinedto afalseupon return if the ClassName was not found.
"Programming comfortably with my PJs." - PT