Posted By

StrawMan on 05/28/12


Tagged

jquery


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

BrockSamsom


Colorize Portions Of String


 / Published in: jQuery
 

Colorize Portions Of String

  1. //Colorize Portions Of String
  2. $('div.tr_history_use_sub_div').each(function() {
  3. var $text = $(this).text();
  4. if($text.indexOf('+') >= 0) {
  5. $(this).css({
  6. 'color' : 'green'
  7. });
  8. } else if($text.indexOf('-') >= 0) {
  9. $(this).css({
  10. 'color' : 'red'
  11. });
  12. }
  13. var go_pos = $text.search(/ゴールド/i);
  14. var go_txt = $text.substr(go_pos, 4);
  15. if(go_txt === 'ゴールド') {
  16. var t = $(this).text();
  17. t = t.replace(go_txt, '<span class="gold_black">ゴールド</span>');
  18. $(this).html(t);
  19. }
  20. });

Report this snippet  

You need to login to post a comment.