Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7685601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:17:14+00:00 2026-05-31T19:17:14+00:00

Well ive got this code that creates a table from JSON data. If a

  • 0

Well ive got this code that creates a table from JSON data. If a specific value is true, i would like that cells color to be set to red. I feel like what i have should work, but it doesnt….

I would really like to do this with jquery if possible and im sure it is. I was able to set the entire row using my function with the class name. I was also able to get the specific cell to change when clicked. But i just cant seem to get it to set it when the page loads

<!DOCTYPE html>
<html>
<head>

  <title>jQuery Test Stuff</title>

  <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>

<script type="text/javascript">
$(window).load(function(){
$(document).ready(function() {



    var info = [{"Id":1,"Text":"Changed Location B","Summary":"PED","Complete":true},
    {"Id":2,"Text":"MA_HolyOke","Summary":"MAT","Complete":true},
    {"Id":3,"Text":"MA_NEMC","Summary":"PED","Complete":false},
    {"Id":4,"Text":"MA_South Shore","Summary":"ICU","Complete":true},
    {"Id":5,"Text":"MA_NEMC","Summary":"MAT","Complete":false},
    {"Id":6,"Text":"MA_NEMC","Summary":"MAT","Complete":false},
    {"Id":7,"Text":"MA_NEMC","Summary":"MAT","Complete":true},
    {"Id":8,"Text":"MA_NEMC","Summary":"ICU","Complete":true},
    {"Id":9,"Text":"MA_NEMC","Summary":"ICU","Complete":true},
    {"Id":10,"Text":"MA_NEMC","Summary":"MAT","Complete":false},
    {"Id":11,"Text":"MA_NEMC","Summary":"PED","Complete":true},
    {"Id":12,"Text":"MA_NEMC","Summary":"PED","Complete":false},
    {"Id":13,"Text":"MA_NEMC","Summary":"MAT","Complete":true},

    ];







    for (var i = 0; i < info.length; i++)
        {
            var hospId = info[i].Id;
            var subText = info[i].Summary;
            var hospital = info[i].Text;
            var complete = info[i].Complete;

            var fred = ('<td class="something"> ' + hospId +  ' </td>')



            if(subText == "PED")
            {

                $("#PED").append(fred);

            }

            if(subText == "MAT")
            {

                $("#MAT").append(fred);

            }

            if(subText == "ICU")
            {

                $("#ICU").append(fred);

            }

            if(complete == true)
            {
                //alert(fred);
                $(fred).css("background-color","red");

            }


        }









});
});

</script>


</head>
<body>
  <table id='beds' cellpadding="20">
  <tr id="PED"><td>PED</td></tr>
  <tr id="MAT"><td>MAT</td></tr>
  <tr id="ICU"><td>ICU</td></tr>
  </table>


</body>


</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:17:16+00:00Added an answer on May 31, 2026 at 7:17 pm

    You forgot $ in front of your markup. Should be:

    var fred = $('<td class="something"> ' + hospId +  ' </td>')
    

    fiddle: http://jsfiddle.net/Rc33n/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this code I'm trying to use to export data from Excel to
I've got an after insert trigger that works well. However, I want it to
I've got to develop a multi-language code generator in C#. Well actually the idea
I've got a class which inherits from a List<MagicBean> . It works well and
Well, now that I've finally got my stupid ODBC stuff configured, I took a
I've got a response that sends back an entire table. N number of rows
I've got a GtkTable that contains several GtkLabel's of data that it displays. These
I've got a data collection routine that takes about 10 seconds to run, then
I've got a couple of solutions that represent a framework of code that I've
I've got this workbook I've been trying to get to work via macro code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.