>     number = '' + this.html;

You meant $(this).html() I think. However, since you're writing a
plugin here, the "this" is a jQuery object and not a DOM object.
Here's the way I'd do it, assuming the numbers are all integers (no
decimal points):

jQuery.fn.addCommas = function(){
  return this.each(function(){
    var text = $(this).text(), re = /(\d+)(\d{3})/;
    while ( re.test(text) )
      text = text.replace(re, "$1,$2");
    $(this).text(text);
  });
};

Reply via email to