Skip to content

Instantly share code, notes, and snippets.

@gtrufitt
Created April 10, 2013 15:44
Show Gist options
  • Select an option

  • Save gtrufitt/5355779 to your computer and use it in GitHub Desktop.

Select an option

Save gtrufitt/5355779 to your computer and use it in GitHub Desktop.
Wrap a span around the pennies on a price
// Fancy price - add span around the pennies for styling
$.fancyPrice = function(selector){
$(selector).each(function(){
var price = $(this).html();
var decimalPosition = price.indexOf('.');
var afterDecimal = price.substr(decimalPosition,3);
var newPrice = price.replace(afterDecimal,'<span>' + afterDecimal + '</span>');
$(this).html(newPrice);
});
};
$.fancyPrice('.price');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment