Useful JS Code Snippets

A collection of some useful/random JavaScript code snippets.

Active class on list item

When clicking on a list item, the item will be styled to show it has been actively clicked on, and all other items will revert to normal styling.

For example, list items all with the class of 'subFolder':

    $(".subFolder").click(function (event) {
        $(".subFolder").toggleClass("active", false);
        $(this).toggleClass("active", true);
    });

...

<style>
    .active {
        background: #2b96c7;
    }
    .active a {
        color: whitesmoke !important;
    }
</style>


Created: 24-Jul-2023


Login to add comments