How to insert links into a js file in django so that the function changes the style files?

I’m trying to make a button that changes the site to a dark/light theme. In vs code, my code works completely, but nothing happens in pycharm on django.

script.js file:

let switchMode = document.getElementById("switchMode");

switchMode.onclick = function () {
    let theme = document.getElementById("theme");

    if (theme.getAttribute("href") == "dark-mode.css") {
        theme.href = "light-mode.css";
    } else {
        theme.href = "dark-mode.css";
    }
}

button:

    <li class="nav-item" id="switchMode">
        <img class="header__moon" src="{% static "img/Moon.svg" %}" alt="" >
    </li>