title: Сheck for a non-existent class
body: <p>I have some code that updates <code>div</code> and adds +1 value</p>
  <pre><code>$(function() {
    $.ajaxSetup({
      headers: {
        'X-CSRF-TOKEN': $('meta[name=&quot;csrf-token&quot;]').attr('content'),
      },
    });
  
    $('.like-button').on('click', function(event) {
      event.preventDefault();
      var targetElement=$(this);
      $(this).addClass('active');
  
      let href = $(this).attr('href');
  
      $.ajax({
        url: href,
        type: 'POST',
        success: function() {
          var current = parseInt(targetElement.find('.comments-sub-header__item-icon-count').html());
            targetElement.find('.comments-sub-header__item-icon-count').html(current+1)
       },
      });
    });
  });
  </code></pre>
  <p>On click, I add the class <code>active</code>, <code>$(this).addClass('active');</code> and an action occurs which in <code>succes</code>, when I click again, this action is triggered again, so I need to check that such an action should be done only when the <code>active</code> class does not exist</p>
  <p>I try to check this way</p>
  <pre><code>success: function() {
          if (targetElement.hasClass('active')) { 
            return false;
          }
  
          else {
            var current= parseInt(targetElement.find('.comments-sub-header__item-icon-count').html());
            targetElement.find('.comments-sub-header__item-icon-count').html(current+1)
          }
       },
  </code></pre>
  <p>But this does not work, there are no errors, just the value +1 is not added</p>
  <p>This is how, in principle, the system for adding likes works for me</p>
  <pre><code>Route::post('article/{id}', 'App\Http\Controllers\ArticleController@postLike');
  </code></pre>
  <pre><code>public function postLike($id, Request $request) {
          $article = Article::find($id);
  
          if(!$article){
              return abort(404);
          }
  
          $type = $request-&gt;input('type');
        
          if ($article-&gt;hasLikedToday($type)) {
              return response()
                  -&gt;json([
                      'message' =&gt; 'You have already liked the Article '.$article-&gt;id.' with '.$type.'.',
                  ]);
          }
      
          $cookie = $article-&gt;setLikeCookie($type);
        
          $article-&gt;increment(&quot;like_{$type}&quot;);
      
          return response()
              -&gt;json([
                  'message' =&gt; 'Liked the Article '.$article-&gt;id.' with '.$type.'.',
                  'cookie_json' =&gt; $cookie-&gt;getValue(),
              ])
              -&gt;withCookie($cookie);
      }
  </code></pre>
  <pre><code>public function hasLikedToday(string $type)
      {
          $articleLikesJson = Cookie::get('article_likes', '{}');
  
          $articleLikes = json_decode($articleLikesJson, true);
  
          if (!array_key_exists($this-&gt;id, $articleLikes)) {
              return false;
          }
  
          if (!array_key_exists($type, $articleLikes[$this-&gt;id])) {
              return false;
          }
  
          $likeDatetime = Carbon::createFromFormat('Y-m-d H:i:s', $articleLikes[$this-&gt;id][$type]);
  
          return ! $likeDatetime-&gt;addDay()-&gt;lt(now());
      }
  
      public function setLikeCookie(string $type)
      {
          $articleLikesJson = Cookie::get('article_likes', '[]');
  
          $articleLikes = json_decode($articleLikesJson, true);
  
          $articleLikes[$this-&gt;id][$type] = now()-&gt;format('Y-m-d H:i:s');
  
          $articleLikesJson = json_encode($articleLikes);
  
          return cookie()-&gt;forever('article_likes', $articleLikesJson);
      }
  </code></pre>
  <pre><code>&lt;a href=&quot;/article/{{ $article-&gt;id }}?type=heart&quot; class=&quot;comments-sub-header__item like-button {{ $article-&gt;hasLikedToday('heart') ? 'active' : '' }}&quot;&gt;
      &lt;div class=&quot;comments-sub-header__item-icon&quot;&gt;
          &lt;div class=&quot;comments-sub-header__item-icon-count&quot;&gt;
              {{ $article-&gt;like_heart }}
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/a&gt;
  
  &lt;a href=&quot;/article/{{ $article-&gt;id }}?type=finger&quot; class=&quot;comments-sub-header__item like-button {{ $article-&gt;hasLikedToday('finger') ? 'active' : '' }}&quot;&gt;
      &lt;div class=&quot;comments-sub-header__item-icon&quot;&gt;
          &lt;div class=&quot;comments-sub-header__item-icon-count&quot;&gt;
              {{ $article-&gt;like_finger }}
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/a&gt;
  </code></pre>
  <p>When you click on the <code>like-button</code>, this code</p>
  <pre><code>var current = parseInt(targetElement.find('.comments-sub-header__item-icon-count').html());
  targetElement.find('.comments-sub-header__item-icon-count').html(current+1)
  </code></pre>
  <p>adds +1 to the value and updates the div in which this number is +1, but now it turns out that if we click again, we get another +1, and so on. I need to make sure that +1 is added only on the first click, for this I try to use the active class, and make a check that if it is active, then we no longer add</p>