How to assign a Css class on an item based on click

Tags: jquery,html,css

Problem :



$(function() {
    $(".menu ul li").on("click", function(e) {
        var loe = $(this).index();
        $(".menu ul li:nth-child(" + loe + ")").addClass("activeLI");

How can I modify so onclick set the style to the clicked item to activeLI and remove from the rest.

Solution :

Remove the class from all .menu ul li and add it only to $(this) (the clicked element)

$(function() {
    $(".menu ul li").on("click", function() {
        $(".menu ul li").removeClass("activeLI");

    CSS Howto..

    How to change the scrolling text in CSS or JQuery

    How can I change this CSS for desktop browsers only?

    html, css: How to cause a div be presented on top of other divs

    how to change CSS styles dynamically using php/Mysql..i want to create themes that are unique to each user?

    How to get CSS file to affect only a section of HTML

    how to to set chat box based on user id using css

    how to include absolute css path using add_editor_style() in wordpress

    How to make submit input and text input equally spaced

    How to reduce responsively the height of images in the flexbox layout to fit window height?

    How do I keep my footer text from appearing outside my footer

    How to create rounded shapes with css or SVG

    How to use one popup box to display arbitrary number of information respectively?

    how to gap a list in half

    CSS - How to set margin-left dynamically with a fixed value

    Css, text shadow - How to get it overflow off the div

    How to put a background image on a site

    How to show the vertical image into horizontal manner using HTML and CSS?

    How can I style a select option like a table?

    How can I center vertically a div with position absolute and hight = 100px on another div with position relative but with not standard height

    How to use CSS to create a particular stylized, multi-lined text box?

    How to keep the Parent menu hovered while the mouse in child menu in a Dropdown Menu

    How To Avoid Certain CSS coding/commands From Overriding Existing Customisations

    How to create a multi colored circle in html and css

    How does height of a div relate to font size

    Hide and show when click a button

    How do I get 3 horizontal divs to stack in different vertical order or flow when browser width decreases?

    Animate css depending on mouse movement [how can I improve]

    How to add rows to a responsive grid

    How to link Body/Html Backgrounds with CSS in Ipad/Iphone (safari)

    How to design select box using css