Home > DeveloperSection > Forums > setting background-color in jQuery?
Mark Devid
Mark Devid

Total Post:102

Points:714
Posted on    April-08-2013 3:17 AM

 JQuery JQuery 
Ratings:


 1 Reply(s)
 1392  View(s)
Rate this:
Hi Everyone!

I'm trying to make a jQuery that if the value is 130 the color of the background.

Here is my code so far:

function Compute(p, m, f, studno) {
  var average;
  average = parseFloat(p * 0.3) + parseFloat(m * 0.3) + parseFloat(f * 0.4);
  $("#average_" + studno).val(average.toFixed());                           
  if($(this).text()=="130"){
    color:red           
  }       
}

Thanks in advance!


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    April-08-2013 7:58 AM

Hi Mark!

This way!

Use this instead - $(this).css('backgroundColor', 'red');:

function Compute(p, m, f, studno) {
     var average;
     average = parseFloat(p * 0.3) + parseFloat(m * 0.3) + parseFloat(f * 0.4);
     $("#average_" + studno).val(average.toFixed());                            
     if($(this).text()=="130"){
       $(this).css('backgroundColor', 'red');           
     }        
}

Don't want to miss updates? Please click the below button!

Follow MindStick