I am currently working on a website that includes a basic CSS style switcher. The function responsible for handling the theme button clicks is shown below:
<script>
$(function() {
$(".light").click(function(){
$("link").attr("href", "css/lightHome.css");
$(".light").attr("disabled", "disabled");
$(".dark").removeAttr("disabled", "disabled")
})
$(".dark").click(function(){
$("link").attr("href", "css/home.css");
$(".dark").attr("disabled", "disabled");
$(".light").removeAttr("disabled", "disabled")
})
});
</script>
Although the functionality is exactly as I intended, I'm facing an issue where clicking the button doesn't immediately trigger the switch. However, when I move the cursor after clicking, the switch occurs. As my understanding of jQuery is limited, I suspect it may be due to a lack of comprehension regarding DOM processes. Could this be related to missing an "on ready" event?
I have tested by clicking and waiting for several minutes, but the switch only happens after moving the cursor.
The website can be accessed here: