Colorize Portions Of String


/ Published in: jQuery
Save to your folder(s)

Colorize Portions Of String


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.