jquery - How to change CSS all element don't have class `name` on Javascript? -


i write filter product category.

when click category, add class selected element , background of category had selected.

i think problem @ line:

if (!$filterlinks.hasclass('selected') )

i want when user click

  • element,
  • element should go background default white.

    my html structure:

    <ul id="filters">     <li> <a class="selected" data-filter="*"></a> <li>     <li> <a data-filter=".nokia"></a> nokia <li>     <li> <a data-filter=".samsung"></a> samsung <li> </ul> 

    and code:

    var $filterlinks = $('#filters a'); $filterlinks.click(function(){     var $this = $(this);     $this.parents('li').css("background", "red");     if ( $this.hasclass('selected') ) {         return;     }      $filterlinks.filter('.selected').removeclass('selected');     $this.addclass('selected');      // problem @ here, want when user click <li> element,      // <li> element should go background default `white`.     if (!$filterlinks.hasclass('selected') ) {         $filterlinks.parents('li').css("background", "white");     } } 

    full code @ here: https://jsfiddle.net/az2e51c7/

  • here use code:

     $("#filters li").click(function()  {  $("#filters li").removeclass("selected");  $(this).addclass("selected");  }); 

    Comments

    Popular posts from this blog

    ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

    php - How can i create a user dashboard -

    javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -