title: Jquery - change font color based on value of sql result
body: <p>I'm looking to change the font color of a div using jquery where the div is populated by the output of a SQL query.</p>
  
  <p>I have:</p>
  
  <pre><code>$(document).ready(function(){
      $('#foo').each(function(){
          if ($(this).text() == 'bar') {
              $(this).css('color','orange');
          }
      });
  });
  </code></pre>
  
  <p>From a SO search which works fine when the div contains text.</p>
  
  <p>But as this is SQL i'm populating the div with: ".$row['result']."</p>
  
  <p>And this now does not work.  I'm guessing this is because the sql, although being a varchar field is a $variable and isn't 'text' as such?.  </p>
  
  <p>I'm sure this is something simple, but i'm struggling to phrase this in google to return anything useful.</p>
  
  <p>Many thanks.</p>
  
  <p>edit</p>
  
  <p>The whole thing is rather long and before i've tried to add the jquery was all working fine, so i'll just post the additions.</p>
  
  <p>This is within the head:</p>
  
  <pre><code>echo "&lt;script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js'&gt;&lt;/script&gt;";  
  echo "&lt;script type='text/javascript'&gt;";  
  echo "$(document).ready(function(){ $('#foo').each(function(){ if ($(this).text() == 'bar') { $(this).css('color','orange');}});});";
  </code></pre>
  
  <p>Then i echo each row in a while loop:</p>
  
  <blockquote>
    <p>$sql = "SELECT...";<br>
        $result = mysql_query($sql)or die(mysql_error());<br>
        while($row = mysql_fetch_array($result)){<br>
        <code>echo "&lt;div id='foo'&gt;".$row['result']."&lt;/div&gt;";</code><br>
        }</p>
  </blockquote>
  
  <p>The whole document is wrapped in PHP but its not the source of the issue as if i change the div to contain text rather than ".$row['result']."  then the jquery executes on it just fine.</p>