Welcome Guest, Not a member yet? Register   Sign In
Javacript in view issues.-changing td background color
#1

[eluser]reghan[/eluser]
Hello I am having problems using jquery. I am looking to select each cell in my table with the text "Yes" and have the background change to green. If its no then I do not want it to change color. I want this to be able to do dynamically. here is my code so far in my view. my other Jquery plug in works fine, so I know its not a pathing to jquery issue.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

&lt;html&gt;


&lt;head&gt;

&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;


&lt;title&gt;Disaster Recovery - Systems List&lt;/title&gt;

&lt;link href="&lt;?php echo base_url(); ?&gt;style/style.css" rel="stylesheet" type="text/css" /&gt;
&lt;link href="&lt;?php echo base_url(); ?&gt;ts/themes/blue/style.css" rel="stylesheet" type="text/css" /&gt;
[removed][removed]
[removed][removed]
[removed][removed]
[removed]
$(document).ready(function(){
  $("#mytable").tablesorter();}
  
  
);

[removed]

[removed]
   $("td:contains('Yes')").css("text-decoration", "underline");
[removed]

&lt;/head&gt;

&lt;body&gt;

     <div class="content">

         <h1>List of Disaster Recovery Systems</h1>

         <div class="data">&lt;?php echo $table; ?&gt;</div>

         <br />

         &lt;?php echo anchor('bia/add_sys/','add new data',array('class'=>'add')); ?&gt;

     </div>

&lt;/body&gt;

&lt;/html&gt;

any help would be greatly appreciated!! thanks in advance!
#2

[eluser]Matalina[/eluser]
This is how I would do it:

Code:
var $td = $('td');
$td.each(function () {
  var $this = $(this);
  if($this.html() == 'Yes') {
    $this.addClass('yesBg');
  }
});




Theme © iAndrew 2016 - Forum software by © MyBB