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
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
Post a Comment