Inspect the table and format the tr content in bold depending on the values found in two corresponding columns within the same table

Looking to create a responsive table where row content becomes bold if it matches the current date.

Hiding the first-child th & td as they are only needed for a specific function.

Comparing values in

<td data-label="TodaysDate">06-05-2020</td>
and
<td data-label="Date">05-05-2020</td>

If TodaysDate = Date, then the row needs to be made bold.

How can this be achieved using javascript?

https://codepen.io/KGuide/pen/MWwMZzP

function compareCellValues() {

  var rows = $(".ramadan-time").find("tbody tr"); //returns all table rows

  rows.each(function() { //iterate over each row.

    var thisRow = $(this), //this is the current row
        TodaysDate = thisRow.find(".TodaysDate"), //this is the first value
        sDate = thisRow.find(".Date"); //this is the second value

    if (TodaysDate.text() !== sDate.text()) {
     thisRow.css("font-weight", "bold");

    }

    thisRow.find(".TodaysDate").text(parseInt(TodaysDate.text()) - parseInt(sDate.text()));

  });

}

window.onload = compareCellValues();
<!-- CSS code here -->
<!-- Table content here -->

Using the above code snippet to analyze and style the table rows accordingly.

function compareCellValues() {

  var rows = $(".ramadan-time").find("tbody tr"); //returns all table rows

  rows.each(function() { //iterate over each row.

    var thisRow = $(this), //this is the current row
        TodaysDate = thisRow.find(".TodaysDate"), //this is the first value
        sDate = thisRow.find(".Date"); //this is the second value

    if (TodaysDate.text() !== sDate.text()) {
     thisRow.css("font-weight", "bold");

    }

    thisRow.find(".TodaysDate").text(parseInt(TodaysDate.text()) - parseInt(sDate.text()));

  });

}

window.onload = compareCellValues();

Answer №1

My issue was resolved by adjusting the date format from 6-05-2020 to 06-05-2020.

After correcting the data, the script ran smoothly.

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>CodePen - A Pen by KGuide</title>
  <link rel="stylesheet" href="./style.css">

</head>
<body>
<!-- partial:index.partial.html -->
<table class="ramadan-time">
  <thead>
    <tr>
      <th scope="col">TodaysDate</th>
      <th scope="col">Date</th>
      <th scope="col">Day</th>
      <th scope="col">Ramadan</th>
      <th scope="col">April/May</th>
      <th scope="col">Imsak</th>
      <th scope="col">Fajr</th>
      <th scope="col">Sunrise</th>
      <th scope="col">Dhuhr</th>
      <th scope="col">Asr</th>
      <th scope="col">Maghrib</th>
      <th scope="col">Isha</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td class="TodaysDate" data-label="TodaysDate">06-05-2020</td>
      <td class="Date" data-label="Date">05-05-2020</td>
      <td data-label="Day">Friday</td>
      <td data-label="Ramadan">1</td>
      <td data-label="April/May">24</td>
      <td data-label="Imsak">4:17</td>
      <td data-label="Fajr">4:27</td>
      <td data-label="Sunrise">5:45</td>
      <td data-label="Dhuhr">12:20</td>
      <td data-label="Asr">3:49</td>
      <td data-label="Maghrib">6:49</td>
       <td data-label="Isha">8:07</td>
    </tr>

     <tr>
      <td class="TodaysDate" data-label="TodaysDate">06-05-2020</td>
      <td class="Date" data-label="Date">06-05-2020</td>
      <td data-label="Day">Saturday</td>
      <td data-label="Ramadan">2</td>
      <td data-label="April/May">25</td>
      <td data-label="Imsak">4:16</td>
      <td data-label="Fajr">4:26</td>
      <td data-label="Sunrise">5:44</td>
      <td data-label="Dhuhr">12:20</td>
      <td data-label="Asr">3:50</td>
      <td data-label="Maghrib">6:49</td>
       <td data-label="Isha">8:08</td>
    </tr>

    <tr>
      <td class="TodaysDate" data-label="TodaysDate">06-05-2020</td>
      <td class="Date" data-label="Date">07-05-2020</td>
      <d data-label="Day">Sunday</td>
      <td data-label="Ramadan">3</td>
      <td data-label="April/May">26</td>
      <td data-label="Imsak">4:15</td>
      <td data-label="Fajr">4:25</td>
      <td data-label="Sunrise">5:43</td>
      <td data-label="Dhuhr">12:19</td>
      <td data-label="Asr">3:48</td>
      <td data-label="Maghrib">6:50</td>
       <td data-label="Isha">8:10</td>
    </tr> 

  </tbody>
</table>

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

Getting specific information from a cell in a table within an AngularJS application

I need to extract the data "Crab" from this table: Sushi Roll FishType Taste Level Cali Roll Crab 2 Philly Tuna 4 Rainbow Variety 6 Tiger Eel 7 Here is the code snippet that currently re ...

Is it possible to integrate HTML pages as sections within an HTML file using AngularJS?

There are three individuals each working on separate sections of a webpage. One is focusing on moving images, another is devoted to the tab section. This begs the question: 1) Is it feasible to embed all these HTML sections into a single HTML page and dis ...

How can I create editable text using typed.js?

How can I achieve the same text animation effect on my website as seen on the homepage of ? I want to utilize the library available at . Specifically, how do I stop the animation when the text is clicked, allowing users to input their own text? Below is ...

Guide on accessing the fastify application instance within an imported module

Currently, I am working on developing a rest API using Fastify and I am in the process of organizing my code into separate files for better structure. One issue I am facing is how to access the Fastify instance within a file that I import. The following s ...

What are the benefits of keeping PHP separate from HTML?

As I am relatively new to the world of programming, I have been learning how to separate PHP from HTML. However, I am curious to know if there is a difference between executing the following code: <?php $rand="I love apples" ?> <h1>This is a t ...

Creating adjustable absolute positioned elements in Bootstrap 4 for optimal responsiveness

Is there a Bootstrap 4 class that can help me position an absolute yellow color container in a responsive way across all devices, without the need for writing multiple media queries? I want to achieve a screen layout like this on my webpage. Any suggestion ...

In JavaScript, utilize an object that is defined outside of a function

Here is a JavaScript function I have: function status(){ this.functionA = function(){} //Other functions and fields go here } Now, there is another function as well: function create(root){ var server = library(function (port) { //Additional functi ...

Develop a trail of links that reflect the structure of the nodes

The hierarchical structure of nodes is as follows: { "nodes":[ { "assetId":"cfe-3a2b-47e7-b7e9-e2e090ca0d34", "assetName":"IRCTC", "assetType&quo ...

Loading images with CSS media queries is an essential technique for optimizing

Currently, I am exploring options to dynamically load a background image based on the width of the browser window. This way, I can optimize bandwidth usage by only loading the image that will be displayed. I am aware that using the HTML picture tag allows ...

Filtering out specific properties in an array using Angular

I am facing an issue with my Angular filter when inputting text for a specific list. initialViewModel.users = [ {user: 'Nithin',phone: 'Azus', price: 13000}, {user: 'Saritha',phone: 'MotoG1',price: 12000}, {user: ...

Error Encountered: Unable to utilize $(...).mask function with jQuery in ASP.NET using C#

I have encountered an issue while working on a task involving jQuery masked for date. When running the task in HTML, it works perfectly fine. However, when attempting to run it in ASP.NET, I face the problem where 'mask is not a function'. Below ...

The alignment of vertical text can impact the positioning of surrounding text

I am working on creating an online portfolio using HTML and CSS, but I am facing a challenge with vertical alignment. My goal is to have a line of vertical text running down the left side of the screen that displays "My occupation". On the right side of t ...

Contrasting v-on:click and onclick in Vue.js

Can you explain the distinction between v-on:click="..." and using onclick="..." in Vue.js? I am aware that with v-on:click, the handler must be written inside the Vue object (as shown in the documentation example), but what are the be ...

What steps should I take to create a .NET/JavaScript login page that works on IE7, Chrome, Mozilla, and Safari browsers?

I am currently dealing with a .NET login page that functions perfectly in Internet Explorer 7. However, my goal is to enhance its compatibility with Chrome, Mozilla, and Safari. The login code behind looks like this: Protected Sub btnLogin_Click(ByVal se ...

Incorporating dynamic variables into Shopify's settings.html page

Are there ways to integrate templating into Shopify's settings.html? I attempted adding the extension settings.liquid, enabling Liquid templating within the settings document, but it was unsuccessful. In my settings.html file, I include various field ...

Ways to eliminate the blue outline on a checkbox in bootstrap 4.1

Bootstrap 4.1 Is there a way to get rid of the blue border on a checkbox that shows up when it is in focus? https://i.sstatic.net/e77BV.png I attempted to use outline, but it didn't work as I had hoped. This is the code I have been using: <div ...

Change the flyout menu to activate once clicked instead of when the mouse hovers over

Want to add a cool flyout menu action that triggers on click instead of mouseover? The current code triggers the flyouts on mouseover, but I need them to open only when clicked. Specifically, I'd like to change the functionality so that you click on a ...

"Troubleshooting IE-specific problem: Loading dropdown options dynamically with AJAX on change

Struggling with a particular issue lately. I'm attempting to populate a second dropdown menu based on the selection made in the first one using jquery ajax. Surprisingly, it works flawlessly on all browsers except for IE 11. Below is the ajax functio ...

Adjusting elements within nested JavaScript arrays

When using the code below, an empty array containing 7 empty arrays is expected to be created, essentially forming a 7x7 grid. While accessing elements within nested arrays seems to work correctly, attempting to modify their values causes all elements in ...

Error in eclipse formatting: The <script type="text/ng-template"...> tag does not support HTML text

When using the html syntax in a tag, it does not support various html text formats such as text color and auto complete. All html syntax appears in black color. I attempted to use an angularjs plugin, but unfortunately, I could not find a solution.</p&g ...