Is there a way to dynamically update CSS files with JavaScript?

Hey, I'm having some trouble altering the values on my HTML page using JavaScript and CSS. Unfortunately, it's not working as expected. Can someone please take a look at my code and help me out?

// Displaying persons and their records
        for (const person of Object.values(data.recordedData)) {
            let val = 1;
            let tr = document.createElement('tr');
            let thp =  document.createElement('th');

            thp.innerHTML = person.student;
            tr.appendChild(thp);

         // Adding person to dropdown
            let option = document.createElement("option");
            option.innerText = person.student;
            option.value = person.profile; 
            option.parameter = person;
            list.appendChild(option);
           
            for (const value of Object.values(person.values)) {
                let tdp = document.createElement('td');
                tdp.innerText = value;
                // Applying color changes here
                if (value < 5) {
                    tdp.className = 'Red';
                } else {
                    tdp.className = 'Green';
                }
                tr.appendChild(tdp);
            }
            table.appendChild(tr);
            val++
        }    

Answer №1

Perhaps consider trying this approach!

let table = document.getElementById("table");
    let kheaders = document.getElementById("kheaders");
    let list = document.getElementById("list");
    document.getElementById('individual').className = 'hidden';
    let months = [];

    let fetchData = async() => {

        const response = await fetch('./data.json', {method: "GET"})
        return await response.json();
    }

    let showData = data => {
   
        for (const entry of Object.values(data.recordedMonths)) {
            let th = document.createElement("th");
            th.innerText = entry;
            th.id = entry ; 
            kheaders.appendChild(th);
            months.push(entry);
            
        }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Android Troubleshooting: Audio Issue with Hybrid App

Currently, I am utilizing Monaca.mobi to develop a hybrid app. Interestingly, when I compile the app for IOS, everything runs smoothly; however, there seems to be an issue with audio playback on an android device (specifically Nexus 7). Strangely enough, i ...

What is the best way to transfer data from a parent component to a child component in ReactJs?

When dealing with nested react elements, how can you pass values from the parent element to a child element that is not directly inside the parent element? React.render( <MainLayout> <IndexDashboard /> </MainLayout>, document.b ...

Navigating through the execution of a program with the use of

As I navigate my way through learning express, a question has arisen regarding the mechanics of the next() function. Is my understanding correct that when next() is invoked, it immediately initiates the execution of app.get, while anything below next() ...

Securing your Node.js connect-rest REST API with OAuth: A comprehensive guide

After conducting an extensive search on Google for examples related to my query, I was left empty-handed due to the generic name of the "connect-rest" package. My objective is to secure a server side API that I have built using the Node module "connect-re ...

Material-UI icons refusing to show up on the display

I've been working on creating a sidebar component and importing various icons to enhance the UI, but for some reason they are not displaying on the screen. I even tried other suggested solutions without success. <SidebarOption Icon = {InsertComment ...

Slick Slider - Defining the Initial Slide

My website features a dynamic carousel showcasing a basketball team's schedule, with games sorted by date for the current season. I am trying to align the slider to display the upcoming game at the center. How can I designate a specific slide as the ...

Converting a file from a URL to a blob in PHP for use in JavaScript

Attempting to convert an image from a URL to a blob file that can be utilized in JavaScript, but encountering challenges. Is this achievable and if so, how? Current attempts include: // $request->location is the url to the file in this case an ima ...

Static express is failing to load the node_modules folder

Why am I facing difficulties with my website not being able to use the node_modules directory on my server? const express = require('express'); const app = express(); app.use(express.static(__dirname + '/public')); app.listen(8080, &ap ...

Encountering issues with the Justify props in Material UI grid – how to troubleshoot and solve the problem

Can someone help me troubleshoot why justify is not working in this code block? <Grid container direction='column' alignItems='center' justify='center' spacing='1'> <Grid item xs={12}> <Ty ...

What steps do I need to take to set up CORS properly in order to prevent errors with

I encountered the following error message: "Access to XMLHttpRequest at 'api-domain' from origin 'website-domain' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HT ...

Create an HTTP-only cookie from the resolver function in Apollo GraphQL

My objective is to pass the 'res' from my context into a resolver in order to utilize 'context.res.cookie' within my signin function and send an http only cookie. Although my sign-in function works fine, I am unable to see the cookie ad ...

Attempting to display a singular form

Currently, I am working on a MERN app and encountering a small issue... I am developing an application where users can create rooms and within those rooms, they can plan their daily activities. It's similar to a TODO app but more intricate. I wanted ...

The webpage encountered an issue while trying to load a resource: the server returned a 500 (Internal Server Error) status message, preventing the submission of the data

When I use AJAX jQuery to send data via POST, the input name does not get sent and the database shows NULL as the answer. Thank you for any assistance. Below is my JQuery code: $('#btn-save').click(function(){ $.ajax({ url: "<? ...

What is the best way to consistently resize elements to the same pixel value, like "10px", using jquery-ui?

Is there a method to consistently resize a div element by a specific pixel value each time, such as "10px"? I am attempting to achieve this using jquery-ui, where I can resize the element but desire to resize it consistently by a set pixel value. $(child ...

Display sub navigation when clicked in WordPress

I currently have the default wordpress menu setup to display sub navigation links on hover, but I am interested in changing it so that the sub navigation only appears when the user clicks on the parent link. You can view my menu here https://jsfiddle.net/f ...

The odd behavior of how my friends' likes are appearing on Facebook FQL URLs

Hey there! I'm trying to keep track of the number of likes on a specific URL shared by my friends. Here's the code snippet I have: function countURLLikes(url){ FB.api({ access_token:'CAACEdEose0cBABMG67fV8Yn5cHo5fkb ...

Creating fresh CSS by extracting essential selectors from an existing CSS file using Javascript

Is there a method to develop a mini JavaScript function that can parse an HTML document, extract specific selectors from a lengthy CSS file that contains over 2000 lines, and create a new CSS file with only the necessary styles? ...

Chatting in the hot spring with choices

I am looking to create a customizable dialog box in AngularJS where I can pass options such as title and message based on the caller. Essentially, I want to improve upon the standard alert() function. While the documentation has information on passing par ...

What is the most effective method for declaring a constant within a WebComponent?

After receiving questions, I included more details on how I'm utilizing the constants. The main issue I am encountering is that the constants are being added to the global object, which raises concerns about potential name collisions. I created a Web ...

Inquirer doesn't waste time lingering for user input following a prompt

After initiating the prompt, I'm encountering an issue where inquirer doesn't pause for user input and instead immediately advances to the next command line. Below is the code I'm using: import inquirer from 'inquirer'; var link; ...