table column hover

<script>
(function () {
    function clearColHover(table) {
        table.querySelectorAll(".col-hover").forEach(function (el) {
            el.classList.remove("col-hover");
        });
    }
    document.addEventListener("mouseover", function (e) {
        var cell = e.target.closest("td, th");
        if (!cell) return;
        var table = cell.closest("table");
        if (!table) return;
        clearColHover(table);
        var idx = cell.cellIndex;
        table.querySelectorAll("tr").forEach(function (tr) {
            var c = tr.children[idx];
            if (c) c.classList.add("col-hover");
        });
    });
    document.addEventListener("mouseout", function (e) {
        var table = e.target.closest("table");
        if (table && !table.contains(e.relatedTarget)) {
            clearColHover(table);
        }
    });
})();
</script>