I have used someone else's snippet for a background and color colour change which stores the changes in HTML5 session. This is working great for me.
However, I would really like to elaborate on it slightly, and this is where I am stuck.
Here is an example pen I've done, using the code of my current in-progress site: https://codepen.io/iamfnah/pen/NgoyKy
Notice the body background and color classes toggle, using the checkbox beneath the accordion.
Here is the JS from that example:
document.body.style.backgroundColor = sessionStorage.getItem('bg');
document.body.style.color = sessionStorage.getItem('cc');
function dark() {
if ( sessionStorage.getItem('bg') === 'rgb(255, 255, 255)') {
sessionStorage.setItem('bg', 'rgb(51, 51, 51)');
sessionStorage.setItem('cc', '#00ff00');
}
else if (sessionStorage.getItem('bg') == null || undefined) {
sessionStorage.setItem('bg', 'rgb(51, 51, 51)');
sessionStorage.setItem('cc', '#00ff00');
}
else if( sessionStorage.getItem('bg') === 'rgb(51, 51, 51)') {
sessionStorage.setItem('bg', 'rgb(255, 255, 255)');
sessionStorage.setItem('cc', '#333');
}
document.body.style.backgroundColor = sessionStorage.getItem('bg');
document.body.style.color = sessionStorage.getItem('cc');
}
There are CSS classes of the accordion, Bootstrap default classes, which I wish to also control the colour changing of, using the same toggle checkbox.
Those are .panel-body and .panel-default>.panel-heading.
So on toggling to the dark background, I want these styles applied;
.panel-body {
background-color: #1b1b1b;
color: #ccc;
}
.panel-default>.panel-heading {
background-color: #373737;
color: #ccc;
}
I have no idea how you specify such styles within the JS though.
I'm making an assumption, that a couple of lines need adding to the top of the JS for the sessionStorage.getItem to define these classes, and then reference them similarly to the bg and cc ones already in the example?
I've tried, but everything I've tried breaks the script from working.
Can anyone please help with the correct JS I need to extend my current script?
Thanks.