0

Can anybody help me, what i am doing wrong here.

I want to add an class, and when I click on the class, it should remove the class.

$(".processing-signs-direction-cover-sign-direction-selection-process").click(function() {
  $(this).addClass("selected-sign");
});

$(".selected-sign").click(function() {
  $(this).RemoveClass("selected-sign");
  alert(23);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Thank you

Pedram
  • 15,766
  • 10
  • 44
  • 73

1 Answers1

0

The click event is only bound to existing elements. To bind to elements that are dynamically added you can find a solution here.

But why don't you use toggleClass instead?

e.g.

$(".processing-signs-direction-cover-sign-direction-selection-process")
  .click(function() {
    $(this).toggleClass("selected-sign");
  });
.selected-sign {
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="processing-signs-direction-cover-sign-direction-selection-process">click me</div>
H77
  • 5,859
  • 2
  • 26
  • 39