Struggling to style a nested table using CSS

Please take a look at this JSFiddle example for reference.

I am currently working with tablesort and its associated CSS to achieve alternating row colors for the rows containing first and last names. Additionally, I want the rows within the sub-table displaying date and time information to have a white background.

The challenge I am facing is related to having a different class on the first td element under the tablesort table while also needing that class to trigger the toggle functionality for hiding rows. Unfortunately, I am unable to get the CSS implementation correct.

Below is the HTML markup:

<table class="tablesorter" id="table1">
<thead>
    <tr>
        <th>first name</th>
        <th>last name</th>
    </tr>
</thead>
<tbody>
    <tr class="parent-row">
        <td>John</td>
        <td>Appleseed</td>
    </tr>
    <tr class="parent-row-details expand-child" style="display:none">
        <td colspan="6">
            <table class="sub-table" id="SPID" border=1>
                <thead>
                    <th>Date</th>
                    <th>Time</th>
                </thead>
                <tbody>
                    <tr>
                        <td>12/1/13</td>
                        <td>4:00AM</td>
                    </tr>
                    <tr>
                        <td>12/1/14</td>
                        <td>7:00AM</td>
                    </tr>
                    <tr>
                        <td>12/1/15</td>
                        <td>6:00AM</td>
                    </tr>
                </tbody>
            </table>
        </td>
    </tr>
    <tr class="parent-row">
        <td>David</td>
        <td>Goliath</td>
    </tr>
    <tr class="parent-row-details expand-child" style="display:none">
        <td colspan="6">Details about David</td>
    </tr>
    <tr class="parent-row">
        <td>Amie</td>
        <td>Winehouse</td>
    </tr>
    <tr class="parent-row-details expand-child" style="display:none">
        <td colspan="6">Details About Amie</td>
    </tr>
</tbody>

Here is the corresponding CSS:

table.tablesorter {
font-family:arial;
background-color: #CDCDCD;
margin:10px 0pt 15px;
font-size: 8pt;
width: 100%;
text-align: left;
}
table.tablesorter thead tr th, table.tablesorter tfoot tr th {
    background-color: #e6EEEE;
    border: 1px solid #FFF;
    font-size: 8pt;
    padding: 4px;
}
table.tablesorter thead tr .header {
    background: url(http://tablesorter.com/themes/blue/bg.gif) no-repeat 99%;
    background-repeat: no-repeat;
    background-position: center right;
    cursor: pointer;
}
table.tablesorter tbody td {
    color: #3D3D3D;
    padding: 4px;
    background-color: #FFF;
    vertical-align: top;
}
table.tablesorter tbody tr.odd td {
    background-color:#F0F0F6;
}
table.tablesorter thead tr .headerSortUp {
    background: url(http://tablesorter.com/themes/blue/desc.gif) no-repeat 99%;
}
table.tablesorter thead tr .headerSortDown {
    background: url(http://tablesorter.com/themes/blue/asc.gif) no-repeat 99%;
}
table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp {
    background-color: #8dbdd8;
}

table.tablesorter tr.parent-row td {
    background: #8dccc8;
}
table.tablesorter tr.parent-row-details td {
    background: grey;
}
table.sub-table thead tr th {
    background-color: #FFF;
    border: 1px solid #000;
    font-size: 8pt;
    padding: 4px;
}
table.sub-table tbody tr td {
    background-color: green;
    border: 1px solid #000;
    font-size: 8pt;
    padding: 4px;
}

Answer №1

Does this meet your requirements?

http://jsfiddle.net/sarahsmith/rFv92/22/

added > td

$(document).ready(function () {
    $("table.tablesorter tr.parent-row:even > td").css("background-color", "blue");
});

also modified

table.sub-table tbody tr td {
    background-color: white; /* changed to white */
    border: 1px solid #000;
    font-size: 8pt;
    padding: 4px;
}

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

Tips for removing duplicate objects from an array

I am utilizing the underscore.js plugin in my code I experimented with it on jsfiddle var basket=[{ "basketitems":[{"items":[]}], "itemdetails":[{ "amountPledged": "100", "bActivity": "Handloom Wo ...

Enhancing the functionality of an existing framework through the integration of a

My coding style involves a lot of ASP.NET MVC and jQuery, particularly with ajax calls that return json. Lately, I've been tinkering with organizing my code structure by creating an object within the global object which contains success and fail callb ...

Effortlessly implementing interactive form fields in Rails using jQuery

I'm struggling with implementing dynamic form fields in Rails. It seems that the framework does not handle this very smoothly, and I'm also incorporating jQuery into my project. While I have jRails installed, I prefer to write AJAX code unobtrusi ...

Tips on arranging an array based on dates and data in JavaScript?

I have an array with dates and other data that I need to sort based on the dates. I'm unsure of how to go about this. Can someone please assist me? Here is the array in question: 0:{_id: "01-11-2017", CommentCount: 221, Likecount: 141, Followcount: ...

Sencha Touch - List Creation - How to apply a class to the final item in the list

I am currently working on a list creation process using the following format: var listTpl = new Ext.XTemplate( '<div class="menuListItemContainer">', '<h1>MENU</h1>', '< ...

There is an overflow issue where content on the left side is being hidden when the overflow is set to auto

I am attempting to display a content box consistently on both desktop and mobile by utilizing a fixed width and overflow property. :root { --box: rgb(20, 33, 150); --box1: rgb(55, 75, 255); --background: rgb(147, 158, 255); } body { -we ...

Function in React not being successfully passed down between functional components

I have been accustomed to using class components and now I am transitioning into functional components in order to become more proficient with hooks. However, I have encountered an issue where I am struggling to pass a function from one functional compone ...

The error message "Trying to call zmq.zmqVersion as a function, but it's not a function" occured while attempting to import the ZeroMQ

My current project involves creating a react app that can subscribe to an IPC socket using JavaScript code. I chose to use npx create-react-app for this purpose. To handle the subscription, I decided to utilize the npm package zeromq. However, when instal ...

How to retrieve an image from an external source using jQuery

There's a link that looks like this: http://vignette4.wikia.nocookie.net/2007scape/images/c/c1/3rd_age_amulet.png/revision/latest?cb=20141217224859 and I'm trying to figure out how to download it into a specific folder with a specific name usin ...

Using Vue.js with jQuery plugins: A step-by-step guide

Currently in the process of rewriting code to Vue.js, I am interested in incorporating some Jquery plugins, but I am uncertain about the correct method. One plugin I would like to utilize is a scrollbar: I understand that initialization should look someth ...

Ways to manage numerous AJAX actions within a single HTTP request?

Currently, I am utilizing jQuery to create a multipart web page containing a list of links that are updated through periodic AJAX HTTP requests. Each link on the page is triggered by a timer in JavaScript, causing it to make an HTTP request to its designat ...

Troubleshooting: Page Unable to Import/Execute Linked JavaScript on WebStorm with Node.js Backend

I've been following W3School's jQuery tutorial, but I'm encountering some issues with importing scripts to an HTML document hosted on a Node server in WebStorm. I have properly installed and enabled the jQuery libraries under Preferences &g ...

What is the best approach to modify a user-inserted value on a webpage with both javascript and php?

In my PHP code, I have set up a variable that is displayed in an input field for the user. The user has the ability to change this value, however, when I try to retrieve the updated value using JavaScript, it doesn't seem to update. Instead, it remain ...

I am looking to bring in just the tables from a different html/php page

I am currently working on a webpage that includes a php library, header, and other elements. I only need to import specific tables and information from this page onto another screen display, with the tables arranged side by side instead of vertically. My ...

The loading spinner isn't appearing while the function is running

Having trouble displaying a loading spinner while a function is running. I've tried different methods, but the spinner just won't appear. Here's the HTML snippet: <div class="row pt-3" id="firstRow"> <div class="col"> <bu ...

There is an absence of the percentage symbol

Is it possible to display a textbox with a % sign next to it, but the % sign is not showing up? How can I make it appear? Here is the code I have been using: var $weightText = $("<input type='text' id='txtWeightRow' maxlength= ...

Polymer event / callback for appending new child nodes

My current project involves creating a custom element, let's call it <parent-element>, that performs specific actions based on the presence of its childNodes. When I define the element like this: <parent-element> <div> </div&g ...

Is it possible to modify the cell color or highlight in Excel through Node.js?

Hi there, I'm curious if it's possible to highlight a cell in an .csv file using Node.js. I've been able to successfully write to the file, but now I want to emphasize the headings. ...

Refreshing CAPTCHA with the power of PHP and jQuery

Seeking advice on how to dynamically renew the captcha image created by a php script when the "captcha_refresh" is clicked. My current solution works well only in Google Chrome, with other browsers not recognizing it. HTML <img class="captcha_image" s ...

Having trouble with a basic select tag and options not functioning properly in Chrome browser

I encountered an issue where I am unable to expand a simple select tag in Chrome. <select id="filterCategory" class=""> <option>1</option> <option>2</option> <option>3</option> <option>4</option ...