0

So, I have this if statement and I want to add a class to an element I've added it in my if statement but it doesn't add the class.

     $(".project").click(function(){
        if ($(".project-expand",this).is(':visible')) {
          $(".project-expand",this).hide();
        } else if ($(".project-expand",this).is(':hidden')) {
          $(".project-expand",this).show();
          $(".project",this).addClass('item-dropped');
        }
     });
1
  • Can you post the corresponding markup (HTML) Commented Sep 7, 2014 at 15:58

1 Answer 1

3

This line seems wrong to me

$(".project",this).addClass('item-dropped');

You are passing this which already should be the .project element you clicked as a context for your selector. Unless you have a nested .project I don't think jQuery will be able to find the element you are looking for

Replace that line with $(this).addClass('item-dropped');

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

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.