Created
July 10, 2023 11:04
-
-
Save catvinyl/11efb0549f8ebfc8596e3d346c7cbf12 to your computer and use it in GitHub Desktop.
export_all_elements_by_id_or_className.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// License: CC0 1.0 Universal (CC0 1.0) / Public domain (PD) | |
// Name: Export all elements by id or className | |
if (typeof document == 'object'){ // If not browser | |
const dom_elements = document.querySelectorAll('*'); | |
for (let i = 0; i < dom_elements.length; i++) { | |
let e = dom_elements[i]; | |
let id = e.id || e.className; | |
if(id){ | |
// You can put here callback | |
// console.log(id); | |
// callback(e, id); | |
window[id] = e; | |
}else { | |
console.warn('No id or className for', e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://pastebin.com/giJjjirh