SETTING BACKGROUND-COLOR IN JQUERY?

Mark Devid

Total Post:102

Points:714
Posted by  Mark Devid
JQuery 
 1755  View(s)
Ratings:
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!
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: setting background-color in jQuery?

    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');           
         }        
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!