How can you reference a class within a div using CSS?

Below is the code that I've included.

Desired Outcome: Hide the columns with tr class="invalid" when the checkbox is clicked. Display all tr columns when the checkbox is unchecked.

Any help or solution would be greatly appreciated.

Answer №1

If you want to hide certain elements based on the checkbox status, you can use the adjacent selector like this:

#testday input[type="checkbox"]:checked ~ #testtable .invalid {
    display:none;
}

See the snippet below for an example:

#testday input[type="checkbox"]:checked ~ #testtable .invalid {
  display: none;
}
<div id="testday">
  <input type="checkbox" checked><span class="invalid black-border">Tests not in POR</span>
  <table id="testtable" class="tablesorter custom-popup">
    <thead>
      <tr>
        <th data-priority="critical" class="testName">Test Name</th>
      </tr>
    </thead>
    <tbody>
      <tr class="invalid">
        <td class="testName">
          <abbr title="BasicPerformanceMatrixTest">BasicPerformanceMatrixTest</abbr>
        </td>

      </tr>
      <tr class="invalid">
        <td class="testName">
          <abbr title="StripeReadECCFatalDuringPLIRestore_NSGSE-23331">StripeReadECCFatalDuringPLIRestore_NSGSE-23331</abbr>
        </td>

      </tr>
      <tr class="invalid">
        <td class="testName">
          <abbr title="ContextReplayTimes_NSGSE-27617">ContextReplayTimes_NSGSE-27617</abbr>
        </td>

      </tr>
      <tr class="invalid">
        <td class="testName">
          <abbr title="XORRecoveryShouldSkipRetiredPages_NSGSE-27131">XORRecoveryShouldSkipRetiredPages_NSGSE-27131</abbr>
        </td>

      </tr>
      <tr>
        <td class="testName">
          <abbr title="PliDumpECCFatal(XOROn_2Codewords)[unaligned]_NSGSE-22801">PliDumpECCFatal(XOROn_2Codewords)[unaligned]_NSGSE-22801</abbr>
        </td>

      </tr>
      <tr>
        <td class="testName">
          <abbr title="PliDumpECCFatal(XOROff_2Codewords)[unaligned]_NSGSE-22802">PliDumpECCFatal(XOROff_2Codewords)[unaligned]_NSGSE-22802</abbr>
        </td>

      </tr>
      <tr>
        <td class="testName">
          <abbr title="PliDumpECCFatal(XOROff_1Page)_NSGSE-22803">PliDumpECCFatal(XOROff_1Page)_NSGSE-22803</abbr>
        </td>

      </tr>
      <tr>
        <td class="testName">
          <abbr title="PLIECCFatal(SuperXORtest)_NSGSE-23162">PLIECCFatal(SuperXORtest)_NSGSE-23162</abbr>
        </td>

      </tr>
    </tbody>
  </table>
</div>

Answer №2

LIVE EXAMPLE

Styling with CSS

To hide certain elements, utilize the general sibling selector ~. This selector targets the second element only if it follows the first element and both have the same parent.

input[type="radio"]:checked ~ div .hidden {
     visibility: hidden;
}

Answer №3

input[type="checkbox"]:checked ~ #testtable .invalid {
   visibility:hidden;
}

This method seems straightforward.

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

Output MySQL information into an HTML form with radio buttons and an additional text field

Users are able to input product data into a MySQL database through my web form. They can choose between three main suppliers using radio buttons (Sigma-Aldrich, VWR, and Filter-Service), or select 'other' and specify a different supplier in a tex ...

The behavior of React Native margin is applied internally within the object, rather than externally

Visit the link and then open the file login_screen/components/Form.js. Within this file, you will notice that the textInput is styled as follows: textInput: { flex:1, height: 50, marginBottom: 20 } If you observe closely, you'll see ...

I would like to display a preview image with the same ID across several divs

I am looking to add previews within multiple divs in the same container. Here are my code snippets: HTML Code: <div class="thumbnail"> <div id="resim_view"> <img class="image img-thumbnail" src="#" /> </div> & ...

Using HTML/CSS to create custom styled boxes for reusability in Bookdown

I'm looking to create reusable sections for my bookdown project. Successes: I've created a style.css including: .titeldefbox{ display: flex; width: 100%; left: 0; top: 0; position: absolute; background-color: darkslategray; height: ...

AngularJS failing to display HTML content is a common issue encountered

I am a beginner in Angular JS and recently wrote a simple Angular code. However, I am encountering issues with the HTML rendering incorrectly or the expressions not getting evaluated. I could use some help identifying what I might be missing. The version ...

I would like to retrieve my data using my personal API and have them displayed as checkboxes

https://i.sstatic.net/qPSqe.jpgHere is an excerpt of the progress I have made main.html (it's actually a form) <div class="form-group form-check-inline"> <input class="form-check-input" type="radio" name=& ...

Arrange all HTML components in a single horizontal line

I have a query regarding aligning all elements in a single line. This is how it should ideally appear: Initially, I arranged the elements by creating tables and inserting each ProgressBar as Div Elements within table cells. However, this setup seems to b ...

Out of reach: Menu div slides up on click outside

<a class="btn">Click ME </a> <div class="content"> Content </div> $('.btn').click(function(){ $('.content').slideToggle(); }); Check out the example here Everything is working properly, but I have a q ...

Hyperlinks functioning properly in Mozilla Firefox, yet failing to work in Internet Explorer

I'm encountering issues with my links not functioning properly in Internet Explorer. <a style="text-decoration:none;" href="<?php echo base_url();?>index.php/person/create/<?php echo $this->uri->segment(4);?>" > When I check ...

Using HTML - Proper utilization of markup tags, CSS, and OCSS

As someone who is deeply interested in creating clean and efficient markup, particularly with the advancements of HTML5, I have found it challenging to divorce content structure from presentation. After delving into object-oriented CSS and the use of class ...

Showcasing a variety of product titles with the help of CSS

Since the HTML is hosted on another server and I have no control over it, how can I use CSS to style certain list items? For example, The HTML on the server side: <ol> <li>Coffee</li> <li>Milk</li> <li>Orange Juice< ...

how to handle form submission using JavaScript's return method

As a developer, I have created a single page that fetches data from a registration page. On this page, each data row has an "add" and "unfriend" button, with the latter initially disabled. When a user clicks the "add" button, a prompt box appears asking ...

What is the best way to show inline icons within menu items?

Issue Upon selecting an option from the menu, I encounter a problem where the icon (represented by a question mark inside a speech bubble) appears on a different line than the text ("Question"). Fig. 1. Display of menu after selection with the icon and t ...

Tips for arranging files within a directory in Netbeans IDE

I prefer to centralize all CSS files in a single folder for easy access. Below is the path of my CSS directory: css/sampl.css. Here, css represents the folder. This is the code snippet I am using: <link href="/CSS/sampl.css" rel="stylesheet" type="te ...

Tips for shutting down the camera within a modal by utilizing Html5 QrCode Scanner in ASP.NET MVC

Hey there! I'm currently working with the Html5 QrCode library to implement a scanner, and I've integrated it into a modal. However, I'm facing an issue where the camera continues running even after I close the modal. I'm wondering if t ...

Is it possible to have text centered only on desktop devices and left-aligned on mobile devices using Bootstrap 4?

I have the following code for the header where I want two pictures to be at either end, preferably at the corners. The text should be directly in the center on a desktop, and on mobile, all images and text should be stacked. Is that possible? To view the ...

Ways to create a gradual movement for a div upon toggling a class

$(document).ready(function(){ $("#toggle-btn").click(function(){ $(".book").toggleClass("with-summary",1000); }); }); .book { height:500px; width:100%; position: relative; border:1px solid red; } .book-summary { position: absolute; lef ...

Transform jQuery timer functionality to support both minutes and seconds for redirecting, rather than just seconds

Recently, I stumbled upon a fantastic timer and redirect script based on jQuery from the talented folks over at the 'jQuery by Example' website. This script automatically redirects users after a specified number of seconds has elapsed: Here&apos ...

What are some strategies to stop text from causing the container height of the <li> element to expand?

Link to my code on Plunker In my attempt to create a fluid layout, the sidebar of my site consists of a list of links. I am trying to make each <li> element a perfect square, but when I add text inside, it disrupts the dimensions and turns the squar ...

Issue with retrieving data from dataTransfer on 'drop' event due to undefined value

I'm currently working on implementing Drag & Drop functionality using AngularJS directives. Here's the concept I am trying to execute : Check out my codePen However, I keep encountering an error saying 'getData' is undefined. Th ...