title: Like counter javascript
body: <p>I can not run my like counter in javascript. 
  The replacement of the empty heart with the full one works properly but the counter update no. Can someone help me? Thank you</p>
  
  <pre><code>$query2 = mysql_query("SELECT * FROM totlike WHERE id_user_like = $id_user AND id_post_like = ". $risultato['id'].""); 
                        if(mysql_num_rows($query2) ==1) {
          $like='&lt;i class="glyphicon glyphicon-heart" id="'. $risultato['id'] .'"&gt;&lt;/i&gt;';
                        } else {
                      $like='&lt;i class="glyphicon glyphicon-heart-empty" id="'. $risultato['id'] .'"&gt;&lt;/i&gt;';
                        }
  echo '&lt;div class="list" id="list_'. $risultato['id'] .'"&gt;
          &lt;div class="panel panel-default"&gt;
        &lt;div class="btn-group pull-right postbtn"&gt;
          &lt;button type="button" class="dotbtn dropdown-toggle" data-toggle="dropdown" aria-expanded="false"&gt; &lt;span class="dots"&gt;&lt;/span&gt; &lt;/button&gt;
          &lt;ul class="dropdown-menu pull-right" role="menu"&gt;
            &lt;li&gt;&lt;a href="#myModal" role="button" data-toggle="modal" onclick="segnalazione('. $risultato['id'] .');"&gt;Segnala&lt;/a&gt;&lt;/li&gt;
                '. $delete .'
          &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div class="col-md-12"&gt;
          &lt;div class="question" id="question8025"&gt;&lt;a href="profile.php?id='. $risultato['id_user'] .'" class="question-user"&gt;&lt;div class="img imgLiquid imgLiquid_bgSize imgLiquid_ready" style="width: 60px; height: 60px; margin: 0px auto; background-image: url(&amp;quot;download.jpg&amp;quot;); background-size: cover; background-position: center center; background-repeat: no-repeat;"&gt;&lt;img src="download.jpg" id="questionavatar" style="display: none;"&gt;&lt;/div&gt;&lt;/a&gt;
            &lt;div class="media-body"&gt;
              &lt;h4 class="media-heading"&gt;&lt;a href="profile.php?id='. $risultato['id_user'] .'" class="hashtag" rel="nofollow"&gt;'. $risultato['username'] .'&lt;/a&gt;&lt;br&gt;
                &lt;small&gt;&lt;i class="fa fa-clock-o"&gt;&lt;/i&gt; Yesterday, 2:00 am&lt;/small&gt; &lt;/h4&gt;
              &lt;p&gt;&lt;h4&gt;&lt;a href="post.php?id='. $risultato['id'] .'" class="hashtag" rel="nofollow"&gt;'. $status = nl2br($risultato['post']) .'&lt;/a&gt;&lt;/h4&gt;&lt;/p&gt;
              &lt;ul class="nav nav-pills pull-left "&gt;
                &lt;li&gt;&lt;a href="javascript:void(0)" title="" onclick="like(' . $risultato["id"] . ','. $risultato['total_like'] .' );" id="'. $risultato["id"] .'"&gt;'.$like.' '.$risultato['total_like'].'&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;/div&gt;';
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>function like(id_post, tot_like) {
  
    $.ajax({
         type: "POST",
         url: '../ajax/like.php',
         data:{id_post:id_post},
         complete: function() {
             var elem = $('#'+id_post).attr('class');
             if (elem=="glyphicon glyphicon-heart") {
                 $('#'+id_post).removeClass('glyphicon glyphicon-heart').addClass('glyphicon glyphicon-heart-empty');
                 $('#'+id_post).text(tot_like - 1);
              } else {
                 $('#'+id_post).removeClass('glyphicon glyphicon-heart-empty').addClass('glyphicon glyphicon-heart');
                 $('#'+id_post).text(tot_like + 1);
              }
         }
    });
  </code></pre>
  
  <p>When I click the counter goes to -1 or +2</p>