How to dynamically add :checked:nth-of-type selector to every checkbox with native JavaScript?
I tried this. HTML
<input type="radio" name="slider" title="slide2" class="slider-nav"/>
<input type="radio" name="slider" title="slide3" class="slider-nav"/>
And static selectors in CSS
.slider-nav:checked:nth-of-type(1) ~ .slider-inner {
left: 0%;
}
.slider-nav:checked:nth-of-type(2) ~ .slider-inner {
left: -100%;
}
.slider-inner {
position: absolute;
top: 0;
left: 0;
}
My idea is add slider-nav:checked:nth-of-type(NN) ~ .slider-inner dynamically with JS
So, on JacaScript file I have next code:
window.addEventListener("load", (e) => {
let num = document.getElementsByClassName('slider-nav');
for (let i = 0; i < num.length; i++) {
let newClass = 'slider-nav' + ':checked:nth-of-type(' + (i + 1) + ')';
console.log('newClass: ' + newClass);
// HOW TO ADD CLASS TO STYLESHEET NOW?
}
});
And here I don't know how to add properties to the class and how to add new class to StyleSheet? And yes, I'm beginner in JS.
checkedproperty?