/ Published in: jQuery
Colorize Portions Of String
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Colorize Portions Of String $('div.tr_history_use_sub_div').each(function() { var $text = $(this).text(); if($text.indexOf('+') >= 0) { $(this).css({ 'color' : 'green' }); } else if($text.indexOf('-') >= 0) { $(this).css({ 'color' : 'red' }); } var go_pos = $text.search(/ゴールド/i); var go_txt = $text.substr(go_pos, 4); if(go_txt === 'ゴールド') { var t = $(this).text(); t = t.replace(go_txt, '<span class="gold_black">ゴールド</span>'); $(this).html(t); } });