Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save catvinyl/11efb0549f8ebfc8596e3d346c7cbf12 to your computer and use it in GitHub Desktop.
Save catvinyl/11efb0549f8ebfc8596e3d346c7cbf12 to your computer and use it in GitHub Desktop.
export_all_elements_by_id_or_className.js
// 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);
}
}
}
@catvinyl
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment