0

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 div first div still no change to opacity

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

thanks in advance,

11
  • what is expected output? Commented Dec 26, 2014 at 12:54
  • 1
    You really had me going there with opacity : unset, I had to spend a minute looking it up in the standard, as I haven't seen that one before. I couldn't find anything that says you can pass strings to opacity, it has to be a number between zero and one. Commented Dec 26, 2014 at 12:56
  • what you want to as a output ? Commented Dec 26, 2014 at 12:56
  • @vaibs_cool thanks for your response, when i click a each div I want other div's are opacity, Commented Dec 26, 2014 at 12:56
  • 2
    what do you want ,when you move to other div, what does it mean? Commented Dec 26, 2014 at 12:56

4 Answers 4

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

fiddle demo Try this one

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

          });
        });

1 Comment

@vaibas what I expected, that was given by vladimir Bredihin
1

Fiddle demo try this code once

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

		});

Comments

1

Fiddle demo try this code once

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


        });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.