Sathish Sathish - 3 months ago 10
CSS Question

click function using multiple div not working

here I use four

div
's when i click a first
div
, other all
div
are getting opacity its working fine,I want when I move to other
di
v first
div
still no change to opacity

$(document).ready(function () {
$(".category-item").click(function () {
$(this).addClass("black");
$(".category-item").addClass("blue");
});
});


thanks in advance,

Answer

You are write no valid html code - see:

<div class="category-item" >
    <div class="img-responsive center-block">   </div>      
</div>
<div class="category-item" >
    <div class="img-responsive center-block">   </div>          
</div>
<div class="category-item" >
    <div class="img-responsive center-block">   </div>      
</div>
<div class="category-item" >
    <div class="img-responsive center-block">   </div>  
</div>

And js:

$(document).ready(function(){
    $(".category-item").click(function(){
        $(".category-item").addClass("blue");
        $(this).addClass("black").removeClass("blue");
    });


});

See demo