Add CSS styles via Jquery if the value from a getJSON call is a specific value

losimpro

New Member
I'm new to jquery and am hoping for a little help.I have a page that fetches data in \[code\]getJSON\[/code\] format and inserts said data into an element on the page. The page then refreshes every 2 seconds to fetch updated data.Example of the element that is being updated on the page:\[code\]<abbr title="mouse hover description" id="User004">..updated by getJSON..</abbr>\[/code\]Here is how I'm fetching and refreshing the content of the \[code\]abbr\[/code\] element (this works): \[code\]function refreshData() { $.getJSON('http://domain.com/Data.php',function(User) { $.each(User, function(key, val) { $('#'+key).text(val); }); }); } window.setInterval("refreshData()", 2000);\[/code\]What I'm trying to accomplish is to:
A) Add CSS styles if the key \[code\]user004\[/code\] has the value 2.
B) Add CSS styles if the key \[code\]user004\[/code\] has the value and another key \[code\]user007\[/code\] is 3. This is what I have today for the first issue, but I know it's incorrect:\[code\]$.getJSON('http://domain.com/Data.php',function(User) { $.each(User, function(key, val) { $('#'+key).text(val) { if ($('#user004:contains("2")')) { $("#"+key).css({color: '#9a4d9e', cursor: 'default'}); } } }); });\[/code\]
 
Back
Top