Search

just show me the code

Tuesday, February 16, 2010

Javascript RegEx

this will format the 2nd column to nowrap

will also replace 'xxxx' with <b>xxx</b> in the 5th column

   42 
   43     <script type="text/javascript">
   44         $(function() { 
   45             $('tr>td:nth-child(2)').css('white-space', 'nowrap'); 
   46             $('tr>td:nth-child(5)').each(function() {  
   47                 var regex = new RegExp("\'(.[^ ]*)\'", "g"); // look for  'name'   g=globaly
   48                 var replace = '<b>$1</b>';                       // turns 'name'  =>  <b>name</b>
   49                 var t = $(this).text().replace(regex, replace);
   50                 $(this).html(t); 
   51             }); 
   52         });
   53     </script>

Contributors