Skip to content

Instantly share code, notes, and snippets.

@emaildano
Last active September 6, 2017 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emaildano/c2f9a5c1e838ae2ce2f0c9f6ecd17fde to your computer and use it in GitHub Desktop.
Save emaildano/c2f9a5c1e838ae2ce2f0c9f6ecd17fde to your computer and use it in GitHub Desktop.
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