Jump to content

Help with comparing the value of a div ID


tqla

Recommended Posts

I'm having difficulty with this function. I'm using jquery. The number in #cfp will be anything from 1 to 11,000. My function below should display the word Excellent, Good, Average or Poor depending on the number. But it doesn't work. It doesn't seem to be comparing the vars correctly and will show two words at times. What am I doing wrong? Thanks.

 

To test it I've made the var rating

var rating = '3000';

but it still doesn't quite work. Am I doing it right or is there a better way to do this comparison?

 

function rating(){
var rating = $("#cfp").text();

if(rating < '2500'){
var myDiv1 = document.getElementById("rating");
myDiv1.appendChild(document.createTextNode("Excellent"));
}else if(rating > '2501' && rating < '6999'){
var myDiv1 = document.getElementById("rating");
myDiv1.appendChild(document.createTextNode("Good"));
}else if(rating > '7000' && rating < '10000'){
   	var myDiv1 = document.getElementById("rating");
  	myDiv1.appendChild(document.createTextNode("Average"));
}else if(rating  > '10001'){
   	var myDiv1 = document.getElementById("rating");
   	myDiv1.appendChild(document.createTextNode("Poor"));
}
};

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.