Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6686117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:08:06+00:00 2026-05-26T05:08:06+00:00

Hoping for a quick peer review here. An associate and I build out a

  • 0

Hoping for a quick peer review here. An associate and I build out a video popchart plugin for a client in south korea (here’s the test site – http://izepic.com/kpopcharts/). My question relates to the activity meter in the header of each vid player. So, I wrote the js below to check each of the social interaction numbers, determine their percentage of the interaction total, and then set the width of each type in the meter itself. Note, specificity for each interaction type was required.

$('.bkp-meter').each(function(index){

// find participation type base numbers
var voteTotal = parseInt($('.bkp-vote-total').eq(index).text());
var facebookTotal = parseInt($('.bkp-facebook-total').eq(index).text());
var twitterTotal = parseInt($('.bkp-twitter-total').eq(index).text());
var googleTotal = parseInt($('.bkp-google-total').eq(index).text());
var commentTotal = parseInt($('.bkp-comment-total').eq(index).text());

var scoreTotal = voteTotal + facebookTotal + twitterTotal + googleTotal + commentTotal;

// find participation type ratio
var votePercentage = (voteTotal / scoreTotal) * 100;
var facebookPercentage = (facebookTotal / scoreTotal) * 100;
var twitterPercentage = (twitterTotal / scoreTotal) * 100;
var googlePercentage = (googleTotal / scoreTotal) * 100;
var commentPercentage = (commentTotal / scoreTotal) * 100;

if(scoreTotal > 2) {

// set meter widths for each participation type
$('.bkp-meter-votes').eq(index).css('width', (votePercentage.toFixed(0) - 2) + "%");
$('.bkp-meter-fb').eq(index).css('width',facebookPercentage.toFixed(0) + "%");
$('.bkp-meter-twitter').eq(index).css('width',twitterPercentage.toFixed(0) + "%");
$('.bkp-meter-google').eq(index).css('width',googlePercentage.toFixed(0) + "%");
$('.bkp-meter-comments').eq(index).css('width',(commentPercentage.toFixed(0)) + "%");

} else {
$(this).parent().parent().addClass('novotes');
}

});

My question: is there a quicker, cleaner way to do this? I mean, it’s working fine so problem solved but it feels very brute force … for my own improvement I’d like to know if there’s a more efficient method and what sort of issues I might run into with this. One note – the percentages didn’t have to be perfect … they just need to give the user a quick shot of what other people are doin’ with that vid.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:08:06+00:00Added an answer on May 26, 2026 at 5:08 am

    $.each() returns two params, one is index and the other is the object itself. You can optimize your selectors by only searching within that context.

    $('.bkp-meter').each(function(index, meter){
    ...
    
    $('.bkp-meter-votes', meter).css('width', (votePercentage.toFixed(0) - 2) + "%");
    $('.bkp-meter-fb', meter).css('width',facebookPercentage.toFixed(0) + "%");
    
    ...
    
    });
    

    Same thing applies to your first block with the $('.bkp-vote-total').eq(index) bits.

    Also note that class selectors are really slow in browsers that don’t support getElementByClass natively (namely IE8 and lower) so beware using them alone like that if it’s a concern. Always provide context: $('#container .bkp-meter')

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am hoping someone can help me out with a quick question I have
Hoping some learned Rails developers here can recommend an existing Ruby on Rails plugin
Hoping someone can give me a hand here.... I have the DataTables jquery plugin
I'm hoping to make a quick script to log-out/restart windows at a set time.
Hoping this will be a quick/easy one, but I can't seem to find the
I was hoping someone could answer my quick question as I am going nuts!
I am hoping that this will have a pretty quick and simple answer. I
Hoping that anybody here knows about a good one: I'm looking for a (free
Hoping for a quick answer (which SO seems to be pretty good for)... I
I am in way over my head, and am hoping anyone here can help.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.