In the head section of my HTML, I have the following stylesheet:
<link rel="stylesheet" href="/templates/jooswatch-v3-5/css/bootswatch/superhero/bootstrap.min.css">
I want to replace this stylesheet with different ones based on changes in the body#main.whatever class (for example, switching between different pages).
For example:
changing from: body#main.itemid113
to: body#main.itemid114
<script>
jQuery(document).ready(function() {
$('body#main.itemid113').replaceWith('<link rel="stylesheet" id="main" href="/templates/jooswatch-v3-5/css/bootswatch/cerulean/bootstrap.min.css" type="text/css" />');
$('body#main.itemid114').replaceWith('<link rel="stylesheet" id="main" href="/templates/jooswatch-v3-5/css/bootswatch/cosmo/bootstrap.min.css" type="text/css" />');
});
</script>
I am struggling to make this change effectively. Can someone guide me on the correct approach?
Would the following solution work?
jQuery(function($){
if ($('.itemid113').length){
$('body').append("<link rel="stylesheet" href="/templates/jooswatch-v3-5/css/bootswatch/cerulean/bootstrap.min.css" type="text/css" />");
};
if ($('.itemid114').length){
$('body').append("<link rel="stylesheet" href="/templates/jooswatch-v3-5/css/bootswatch/cosmo/bootstrap.min.css");
}
});