Is there a way to dynamically add a CSS stylesheet based on the presence of a specific class on a page?
For example, instead of checking the time and loading different stylesheets, I want to load different stylesheets depending on the class present in the HTML:
<script>
<!--
function getStylesheet() {
if(document.body.classList.contains('company')) {
document.write("<link rel='stylesheet' href='company.css' type='text/css'>");
}
if(document.body.classList.contains('contact')) {
document.write("<link rel='stylesheet' href='contact.css' type='text/css'>");
}
if(document.body.classList.contains('enterprise')) {
document.write("<link rel='stylesheet' href='enterprise.css' type='text/css'>");
}
if(document.body.classList.contains('media')) {
document.write("<link rel='stylesheet' href='media.css' type='text/css'>");
}
}
getStylesheet();
-->
</script>
This script will check for the presence of specific classes like "company," "contact," "enterprise," or "media" in the body element and then load the corresponding CSS file.