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');
        }
     });
Wilfredo P
  • 4,070
  • 28
  • 46

1 Answers1

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');

Dogoku
  • 4,585
  • 3
  • 24
  • 34