Seeking assistance in comprehending the method for styling table data using inline CSS in a JavaScript file

I am currently using a JavaScript file that was created for me to update form data based on user selections and display radio buttons along with the corresponding costs.

Although the inline CSS in this script works perfectly fine in Chrome and Firefox, it seems to fail in Safari, Internet Explorer, and Opera.

I cannot figure out why it is not functioning properly across all browsers or how to resolve this issue to ensure consistent performance.

Any insights or suggestions would be greatly appreciated.

function update(sqin,name) {
    $('#display_size').html(name);
    str9 ="<table  style='margin-left:10px;float:left;'>";
    for (index = 0; index < prices[sqin].length; index++) {
        var qty = prices[sqin][index][0];
        str9 += '<tr><td style="padding-top:5px;width:90px;"><input type="radio" id="radio_btn" name="productpr1" VALUE="'+qty+':'+prices[sqin][index][1]+
        '<label for="radio_btn"><span style="font-family: \'Open Sans\', serif;font-size: 20px;">'+qty+'</span></label>'+
    '</td><td style="font-family: \'Open Sans\', serif;font-size: 20px; padding-top:5px;">$'+prices[sqin][index][1]+'</td></tr>';

        if (index == 4) {
            str9 += "</table><table style='margin-left:175px;'>";
        }

    }
    str9 += "</table>";
    $('#price_table').html(str9);

    $('[name="product1[]"]').val("ea "+name+" Die-Cut Decals");

Answer №1

Click on this link to access a helpful FIDDLE.

CSS Styles:

table {
    width: 300px;
}
span {
    color: red;
}
table tr:first-child td {
    background-color: #c0bdbd;
    font-size: 18px;
    text-align: center;
    padding: 8px;
    border-radius: 5px;
}
table td {
    padding-left: 30px;
}
table tr:last-child td {
    font-size: 20px;
    color: white;
    background-color: red;
    padding: 8px;
    text-align: center;
    border-radius: 5px;

}

Edit: There are multiple ways to approach this scenario:

  1. Following your colleague's lead and incorporating EVERYTHING into JavaScript - HTML, CSS, and JS - for display purposes.

  2. Putting the HTML in JavaScript and applying fixed CSS styling within the <style></style> section of your header or an external CSS file.

  3. Setting up the HTML structure with fixed styling, using CSS either inline or in an attached stylesheet, then utilizing JavaScript solely for populating data. This is demonstrated above.

The choice among these three approaches depends on your specific application needs and personal preference. Personally, I avoid using inline CSS styling with JavaScript as it can make the code complex and hard to follow, especially for others reviewing it. Upon examining the code in your question with extensive inline styling, it was overwhelming.

Whenever possible, it's best to first construct the foundation (HTML), apply aesthetics, design elements, colors, and layout (CSS), and then introduce interactivity and functionality (JavaScript) like automating home tasks.

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

Generate a configuration file that allows for the reading and storage of modifications

Is there a way to create a configuration file (JSON) on the local file system using JavaScript where I can write and modify data without losing it when the application is restarted? Any suggestions or solutions for this problem? Thank you for your assista ...

Hero Sticky Transition with 100vhDivElement

My code is giving me some trouble. I want the div with text to stay at the bottom of the hero section with a transparent background. When that div reaches the top, it should stick with a black background. The issue is that I have set it in the javascript v ...

Exploring Angular 7: Understanding the HTML5 Fullscreen API and Overcoming Errors

I am currently using Angular 7 and I am trying to implement a fullscreen button in my app. I have utilized the HTML5 Fullscreen API and created two functions for this purpose: openfullscreen() { // Trigger fullscreen console.log('gg'); ...

invisible recaptcha with synchronous ajax

Hey, I'm trying to figure out a solution on how to obtain the token or a valid response from Recaptcha and then proceed with running the ajax call. Does anyone have any suggestions on how to achieve this in a synchronous manner? Here's the proce ...

Handling errors in Angular and rxjs when encountering undefined returns in find operations

I am currently faced with the challenge of catching an error when the variable selectionId, derived from my route, is null or contains an invalid value. My code structure has a mechanism in place to handle errors when the category variable is undefined, bu ...

Information regarding gender vanishes upon refreshing the page

When the page is refreshed, the variable called jso disappears. Is there an alternative method for storing information that does not involve using a button? The goal is to have it work seamlessly when the page is reloaded without requiring any user action. ...

Encountered an issue with reading the property childnotes of null during data retrieval using ajax in PHP

Hello, I am encountering an error while trying to fetch data using ajax. The error message is "Cannot read property 'childNodes' of null". Can anyone help me identify what might be wrong with my code? I have created a form to search for data with ...

Attempting to modify a JSON file within a React application

I recently obtained a JSON file named 'DealerList.json' which I managed to import into my app using the following code snippet: import DealerList from './json/DealerList' let tasks = DealerList; The tasks now store the JSON data and I ...

Identify the credit card as either American Express or American Express Corporate

My JavaScript code can successfully detect credit card types, but I have encountered an issue. I am unable to differentiate between American Express and American Express Corporate cards. Is there a way to distinguish them or is it impossible to identify wh ...

Sliding through HTML content

Unfortunately, I lack expertise in advanced HTML and CSS. After some investigation, I attempted to create a "content slider" similar to the one on the Redlight Traffic website (an anti-human trafficking organization). However, my efforts have been unsucces ...

What is the best way to incorporate auto refresh in a client-side application using vue.js?

Disclaimer: I have separated my client application (Vue.js) from the server side (DjangoRest). I am utilizing JWT for validating each request sent from the client to the server. Here is how it works - The client forwards user credentials to the server, an ...

How to completely disable a DIV using Javascript/JQuery

Displayed below is a DIV containing various controls: <div id="buttonrow" class="buttonrow"> <div class="Add" title="Add"> <div class="AddButton"> <input id="images" name="images" title="Add Photos" ...

conflict between ng-content and textarea elements

My custom component called my-textarea has a unique template structure: <textarea> <ng-content></ng-content> </textarea> However, when I try to input text into the component using the same method as a regular textarea HTML eleme ...

Displaying an external webpage within a Backbone application

Is it feasible to display an external webpage in a view by using its URL? I am working with Backbone and Handlebars. var AuthorizeInstagramView = Backbone.View.extend({ template: Handlebars.compile(template), initialize: function () { }, ...

iOS: Incorrect element is currently being scrolled by the user

I encountered an unusual scrolling problem on iOS (7 or 8) while browsing www.cahri.com/tests/scroll How can you replicate this issue? Visit the example page on your iPhone/iPad/iOS Simulator in landscape mode Use your right thumb to touch and scroll th ...

Revamp your D3 interactive graph with real-time data updates from the server!

I am looking to enhance a graph in D3 (or another visualization library) by completing the following steps: When a user clicks on an item, like a node within the graph, New data is fetched from the server, The new data is then used to add new edges and n ...

Toggle the visibility of multiple divs by clicking on other divs

I have implemented a script on my webpage to toggle the visibility of certain divs by clicking on anchor tags. I found a solution that seems perfect for my needs, but unfortunately it is not working when I try to integrate it into my own website. I suspec ...

Securing Credit Card Numbers with Masked Input in Ionic 3

After testing out 3-4 npm modules, I encountered issues with each one when trying to mask my ion-input for Credit Card numbers into groups of 4. Every module had its own errors that prevented me from achieving the desired masking result. I am looking for ...

The iOS website won't fully load until the button is tapped two times

- (IBAction)saveButton:(id)sender { NSURL *yourWebURL = [NSURL URLWithString: webpageURLLabel.text ]; NSURLRequest *webRequest = [[NSURLRequest alloc] initWithURL:yourWebURL]; if ([self checkIfValidURL] == YES) { [webpagePreview loadReq ...

Position the select tag adjacent to the textbox

Looking for assistance on how to arrange the <select> tag beside the "Desired Email Address" field within my email registration form. I believe a modification to the CSS code is necessary. Below you will find the HTML and CSS (snippet) related to th ...