Skip to content

Instantly share code, notes, and snippets.

@acheong08
Last active January 11, 2024 11:14
Show Gist options
  • Save acheong08/89a9618c381497bce9bf454983ea4685 to your computer and use it in GitHub Desktop.
Save acheong08/89a9618c381497bce9bf454983ea4685 to your computer and use it in GitHub Desktop.
(function (root, factory) {
if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof module === "object" && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.applyClasses = factory();
}
})(typeof self !== "undefined" ? self : this, function () {
// Function to apply classes to elements with a specific class
function applyClasses(targetClassName, classesToAdd) {
const elements = document.querySelectorAll("." + targetClassName);
console.log(elements);
elements.forEach((element) => {
classesToAdd.split(" ").forEach((cls) => {
element.classList.add(cls);
});
});
}
return applyClasses;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment