System32
Active Coder
So, I am having this page: https://testaca.forumotion.me/t6-vote
There, every post has: "vote-bar-desc" class that holds text such as: "Message reputation : 100% (1 vote)".
What I am trying to do is to loop through each post, set counter (that h4) to the number of votes. I did this
I clear the string, get the number of votes but the issue is the number that it is placed is not correct. This loop gets right away all the values from class "vote-bar-desc" and i get wrong result, of course. So, how to deal with this? If you guys need a way to get total number of posts, you can use this:
There, every post has: "vote-bar-desc" class that holds text such as: "Message reputation : 100% (1 vote)".
What I am trying to do is to loop through each post, set counter (that h4) to the number of votes. I did this
JavaScript:
$(document).ready(function(){
$(".post-body").each(function () {
let position = $(".vote-bar-desc").text().lastIndexOf("(");
let reputation = $(".vote-bar-desc").text().slice(position).replace(/[^0-9\.]+/g, "");
$(".personal-vote h4").text(reputation);
});
});
I clear the string, get the number of votes but the issue is the number that it is placed is not correct. This loop gets right away all the values from class "vote-bar-desc" and i get wrong result, of course. So, how to deal with this? If you guys need a way to get total number of posts, you can use this:
JavaScript:
let numOfPosts = $('.post-body').children('div').length;