Last active
January 11, 2024 11:14
-
-
Save acheong08/89a9618c381497bce9bf454983ea4685 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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