I was trying to style a span attached to a checkbox input with JavaScript. It is working but when refreshing the page on input checked, the applied style is not maintained.
<input class="" type="checkbox"
id="new"
name="new"
value="New">
<label class="" for="new" id="">
<span id="newFilter">English Language</span>
</label>
<script>
const checkbox = document.querySelector("#new");
checkbox.addEventListener('change', function () {
if (checkbox.checked) {
document.querySelector("#newFilter").style.backgroundColor = "#272727";
document.querySelector("#newFilter").style.color = "#ffffff";
} else {
document.querySelector("#newFilter").style.backgroundColor = "#ffffff";
document.querySelector("#newFilter").style.color = "#272727";
}
});
</script>