Users Pricing

forum

home / developersection / forums / how can i set different class for div cheking the json data

How can I set different class for div cheking the json data

Aaron Douglas 2422 20 Jun 2013
Hi Mindstickians,
How can I check true or false from json and put different css for div if true or false:
For example json:
{
    "Object": [
    {
        "test": true,
        "number": "001"
    }, {
        "test": false,
        "number": "002"
    }, {
        "test": false,
        "number": "003"
    }, {
        "test": true,
        "number": "004"
    }]
}

and i created html:
<div class="test" id="001">001</div>
<div class="test" id="002">002</div>
<div class="test" id="003">003</div>
<div class="test" id="004">004</div>

I tried something like this but it is wrong...
if (test == 'true') {
$(".test").css("background-color", "blue");
} else {
$(".test").css("background-color", "red");
}

Thanks in advance for any recommendations or solutions.

1 Answers