Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Percentage off Month Plans
<div class="plan-box">
  <div class="dc-table__plans" data-annual-discount="10">
    <div class="amimoto-pricing-data" data-monthly="30">$<span class="price">30</span></div>
    <div class="amimoto-pricing-data" data-monthly="60">$<span class="price">60</span></div>
  </div>
</div>


<div class="plan-box">
  <div class="dc-table__plans" data-annual-discount="15">
    <div class="amimoto-pricing-data" data-monthly="600">$<span class="price">600</span></div>
    <div class="amimoto-pricing-data" data-monthly="900">$<span class="price">900</span></div>
  </div>
</div>
function percentage(num, per) {
  return (num/100)*per;
}

$('.plan-box').each( function() {
  var discount = $(this).find('.dc-table__plans').data('annual-discount');

  $(this).find('.amimoto-pricing-data').each( function() {
    var annual_full = $(this).data('monthly') * 12;
    var annual_off = annual_full - percentage(annual_full, discount);
    $(this).attr('data-annual', annual_off);
  });

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment