---
title: "How can I set different class for div cheking the json data"  
description: "How can I set different class for div cheking the json data"  
author: "Aaron Douglas"  
published: 2013-06-20  
updated: 2013-06-20  
canonical: https://www.mindstick.com/forum/1241/how-can-i-set-different-class-for-div-cheking-the-json-data  
category: "json"  
tags: ["json"]  
reading_time: 1 minute  

---

# How can I set different class for div cheking the json data

Hi Mindstickians,\
\
How can I [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) [true or false](https://www.mindstick.com/forum/160329/how-can-you-convert-a-value-to-a-boolean-true-or-false-in-javascript) from [json](https://www.mindstick.com/forum/34446/convert-json-string-to-object) and put different css for div if true or false:\
\
For example json:\
\
{\
"Object": [\
{\
"[test](https://yourviews.mindstick.com/story/1427/explosive-facts-about-trinity-test-world-s-first-nuclear-bomb)": true,\
"number": "001"\
}, {\
"test": false,\
"number": "002"\
}, {\
"test": false,\
"number": "003"\
}, {\
"test": true,\
"number": "004"\
}]\
}\
and i created [html](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript):\
\
<div [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)="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](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp)-[color](https://www.mindstick.com/articles/77/how-to-split-form-background-color-in-c-sharp)", "blue");\
} else {\
$(".test").css("background-color", "red");\
}\
\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams) for any recommendations or solutions.

## Replies

### Reply by AVADHESH PATEL

Hi,\
For checking [true](https://yourviews.mindstick.com/view/81326/boycott-chinese-products-dream-will-come-true) or false from json try as following\
\
**$.each(json.Object, function(index, value) {** **$number = $("#"+value.number);** **if(value.test) $number.css("background-color", "blue");** **else $number.css("background-color", "red");****});**\
another way as following **\****$.each(json.Object, function(index, value) {** **$("#"+value.number).css("background-color", (value.test ? "blue" : "red"));****});****\**I hope it helpful for you.


---

Original Source: https://www.mindstick.com/forum/1241/how-can-i-set-different-class-for-div-cheking-the-json-data

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
