I have a template which im trying to change the content of a span using getElementById.innerHTML in my ajax success function however, it is not working. I do not see what the issue is since when I print out my data it is correct. Currently I have template like this:
<div class="post-ctr">
<div>
<span id="like-count-d"></span>
</div>
<div class="like-section">
<!-- likeBtn Form is here which gets updated -->
</div>
</div>
my jQuery code is:
$(document).ready(function (e) {
$('.post-ctr').on("click", ".likeBtn", function (e) {
var btn = $(this)
e.preventDefault();
e.stopImmediatePropagation();
var tk = $(this).attr("data-token");
$.ajax({
type: "POST",
url: $(this).attr("data-url"),
dataType: 'json',
data: { 'csrfmiddlewaretoken':tk },
success: function (data){
$(btn).closest(".like-section").html(data.post_likes);
$(document).getElementById('like-count-d').innerHTML = data.likescount;
},
error: function(rs, e){
console.log(rs.responeText);
},
});
});
})
How can I manage to update the span
element with that id?