title: change an element's text with variable id
body: <p>I am designing a social network that has timeline and there is like button. I use AJAX to apply the like button on the server side. the problem is that I want to change the number of like for each post immediately after they have liked successfully. Because my elements are generated by for-each, I want to change the number of like for the exact element, I really have a problem with it.I am using thymeleaf.</p>
  
  <p>I am looking for an idea that how to do this.</p>
  
  <p>here is my html code:   </p>
  
  <pre><code>&lt;div class="col-sm-4"&gt;
     &lt;div class="row" &gt;
        &lt;div class="col-sm-12"&gt;
        &lt;img th:if="${tweet.isFavorited()}" src="../static/images/like.png" th:src="@{/images/like.png}" th:class="like-img" th:id="${tweet.getId()}"  width="35" height="35"/&gt;
        &lt;img th:if="${!tweet.isFavorited()}"  src="../static/images/dislike.png" th:src="@{/images/dislike.png}" th:class="like-img"  th:id="${tweet.getId()}"   width="35" height="35"/&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row"&gt;
     &lt;div class="col-sm-12" &gt;
       &lt;h6 th:if="${tweet.isRetweet()}" th:class="like-count" th:id="${tweet.getId()}"  th:text="${tweet.getRetweetedStatus().getFavoriteCount()}"&gt;&lt;/h6&gt;
       &lt;h6 th:if="${!tweet.isRetweet()}" th:class="like-count"  th:id="${tweet.getId()}"  th:text="${tweet.getFavoriteCount()}"&gt;&lt;/h6&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>and it is my script code:</p>
  
  <pre><code>$(function () {
    $(".like-img").click(function () {    
      event.preventDefault();
  
      var $post = $(this);
      var toSend = {
          "tweetId": this.getAttribute("id")
      }
  
      $.ajax({
          type : "POST",
          contentType: "application/json; charset=utf-8",
          url : "like",
          data : JSON.stringify(toSend),
          dataType : 'json'
      }).done(function (data) {
          if(data.status == "success") {
              if ($($post).attr("src") == "/images/dislike.png") {
                  $($post).attr('src','/images/like.png');
              }
              else {
                  $($post).attr('src','/images/dislike.png');
              }
  
              return false;
          }
      });        
    });        
  })
  </code></pre>