What is the method for altering the appearance of grid columns with javascript?

What modifications do I need to make in JTML and Javascript?

var opac;
    function checkfun()
    {
    opac=(Array.from(document.querySelectorAll('input[type="checkbox"]'))
                              .filter((checkbox)=>checkbox.checked)
                            .map((checkbox)=>checkbox.value));
    }
body
    {
        display: flex;
        font-family: "Montserrat", sans-serif;
    }


    .form
    {
        width: 15vw;
        height: 500px;
        border: 1px solid black;
    }
    .mySidebar
    {
        height: 500px;
        display: block;  
    }

    .mySidebar ul
    {
        font-size: large;
        font-weight: bold;
        color: rgb(110, 110, 110);
    }
    .mySidebar li
    {
        font-size: medium;
        font-weight: normal;
        color: black;
        list-style: none;
    }
    /*--------------------------------------------------------------*/
    .color-block
    {
        margin-left: 30px;
        width: 70vw;
        display: block;
    }

    .col-sm-4
    {
        margin-bottom: 30px;
    }
    .data-grid
    {
        border: 1px solid rgb(189, 189, 189);
        border-radius: 5px;
        max-height: auto;
        display: block;
    }
    /*-----------------colors-----------------*/
    .red{
        background: red;
        widows: 100%;
        height: 400px;
    }

    .blue{
        background: blue;
        widows: 100%;
        height: 400px;
    }

    .green{
        background: green;
        widows: 100%;
        height: 400px;
    }

    .yellow{
        background: yellow;
        widows: 100%;
        height: 400px;
    }
<!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
    </head>
    <body>

    <!-- Sidebar/menu -->
    <div class="form">
        <div class="mySidebar">

            <div >
                <ul >Colours
                    <li><input type="checkbox"  name="a" value="Red"   onclick="checkfun()"> Red</li>
                    <li><input type="checkbox"  name="a" value="Blue" onclick="checkfun()"> Blue</li>
                    <li><input type="checkbox"  name="a" value="Green"  onclick="checkfun()"> Green</li>
                    <li><input type="checkbox"  name="a" value="Yellow"      onclick="checkfun()"> Yellow</li>
                </ul>

                <ul>Color Value
                    <li><input type="checkbox" name="a" value="5" onclick="checkfun()"> 5</li>
                    <li><input type="checkbox" name="a" value="6" onclick="checkfun()"> 6</li>
                </ul>
            </div>
        </div>
    </div>

    <!-- Sidebar/menu -->
    <div class="color-block">
        <div class="row">

            <div class="col-sm-4">
                <div class="data-grid">
                    <div class="red">
                    </div>
                </div>
            </div>

            <div class="col-sm-4">
                <div class="data-grid">
                    <div class="blue">
                    </div>
                </div>
            </div>

            <div class="col-sm-4">
                <div class="data-grid">
                    <div class="green">
                    </div>
                </div>
            </div>

            <div class="col-sm-4">
                <div class="data-grid">
                    <div class="yellow">
                    </div>
                </div>
            </div>

        </div>
    </div>


    </body>
    </html>

This is the link to a codepen: CodePen

I am looking to implement a functionality where when I check a checkbox, the corresponding color grid should be opaque while others remain transparent. For example, if I select Red, only the red color grid should be opaque and the rest transparent.

Please provide guidance on this.

Answer №1

If you have any inquiries regarding the code, please don't hesitate to ask!

document.querySelectorAll("input").forEach(element => {
        element.addEventListener("change", event => {
            var box = document.getElementById(event.target.value);
            if (event.target.checked) {
                box.style.display = '';
            } else {
                box.style.display = "none";
            }
        })
    })
.box {
        width: 5em;
        height: 5em;
    }

    #red {
        background: red;
    }

    #green {
        background: green;
    }
<li><input type="checkbox" value="red" checked>Red</li>
<li><input type="checkbox" value="green" checked>Green</li>

<div>
    <div class="box" id="red"></div>
    <div class="box" id="green"></div>
</div>

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

Cycle through items and switch states using classList in JavaScript

Instructions: Utilize javascript and the classList property to change which elements have the .highlight class. Iterate through all the <li> elements and toggle the .highlight class on each one. Do not make any changes to the HTML and CSS. Your end ...

Rendering the HTML5 canvas within a console environment

I am looking to create images of humans on the console using nodejs. In order to achieve images of higher quality, I require a library or module that can facilitate drawing images in the console. Some options available include imaging and console-png. How ...

Dreamweaver's JSON stringify works perfectly in preview mode, but fails to function when accessed from the .AIR file after application creation

For a while now, I've been working on a basic application using Adobe AIR, specifically the HTML and JavaScript version. What this application does is submit a form to an online URL, with the form values being converted to JSON strings. In order to ...

Modify the static navigation menu to a dynamic menu in Wordpress

Currently, I am attempting to transform my static navigation menu into a dynamic WordPress navigation menu. This is the code that I currently have: <nav> <ul id="menu"> <?php $pages = array( 'in ...

Apply a dual-color gradient background vertically

I am trying to figure out how to achieve a two-tone background color in an HTML document. I know this question has been asked before, but I specifically want the colors to be split vertically rather than horizontally. ...

The dimensions of the cards adjust automatically when the flex direction is set to row

My cards, created in CSS and React.js, have a set height and width. However, when I change the flex direction from column to row, the cards automatically shrink in size. Why is this happening? Card's CSS and JS code CSS .card{ height: 50%; w ...

There was a unexpected JSON response from the Django backend that triggered an alert in the Chrome

Trying to send back a JSON file to the Chrome extension for user display. The query is reaching the server without issues, and the fetched URL does return the JSON file when accessed directly. However, the Chrome extension displays an "undefined" message i ...

Choose from a variety of video play options

Being new to javascript, I've successfully combined two functions that control video playback, but they seem to be conflicting with each other. The first function is designed to offer custom pause and play controls for the video // VIDEO CONTROLS STA ...

Ways to resize column widths in tree views on Odoo version 10?

I have been struggling to adjust the column width of the columns in my tree view. I have attempted a few different solutions: Trying to change the width attribute in the field tag: width="100px" or width="15%%" Using the style att ...

Position an image in the center and add a div below it

I am seeking guidance regarding two specific questions. My objective is to showcase an image in its true size while positioning it at the horizontal center of the screen (not the exact center), followed by a div containing text directly underneath the imag ...

Troubleshooting issue with Django development server causing HTML5 video element to become non-seekable

My Django app is currently serving a webpage with an HTML5 video element, but I've encountered a strange issue. The video.seekable property is returning a timeRanges object with a length=0, when it should actually be length=1. Unfortunately, this mea ...

Tips for implementing personalized command buttons in Kendo Grid with AJAX request utilizing JavaScript

I am struggling with implementing custom command buttons in a Kendo grid that makes an AJAX call using JavaScript to call a web API post action with dynamic parameters (start, stop, restart) behind button clicks. datasource dataSource = new ken ...

What is the technique for moving a slider-like checkbox slider to one of its labels when they are clicked on?

Is there a way to make the switch slider move to the word the user clicked on (medium or large)? I'm not sure if I can track the movement of the switch slider with JavaScript or if it's possible to do with CSS. Right now, I have only created a si ...

Troubleshooting a Hover Problem in Firefox

Chrome is rendering the following code perfectly fine, but Firefox seems to be having trouble applying the hover effect. HTML <!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="stylesheet.css"/> ...

The latest update of NextJS, version 13.1.4, encounters issues when implementing SCSS support with the error message "Module next/dist/compiled/sass-loader/fibers.js not

After setting up a new NextJS project, I decided to incorporate SCSS support. The guidelines provided in the documentation seemed straightforward. Following the installation instructions and including an import of SCSS as shown below: import "@/styles ...

Exploring the latest features in Bootstrap 4 Alpha and enhancing your

Rumors have it that Bootstrap 4 will make its debut during the year 2016. When duty calls for an upgrade, is a complete re-write truly the best solution? Tackling such a project from Boostrap 2 to 3 was no small feat, and I find myself hesitant to take on ...

Preventing default events and continuing with jQuery

Currently, I am working on a Django project and have integrated the Django admin along with jQuery to insert a modal dialog between the submission button and the actual form submission process. To accomplish this, I have included the following code snippe ...

The integration of Angular 6 with AngularJS components fails to load properly in a hybrid application

Currently, I am in the process of upgrading a large AngularJS version 1.7.3 to a hybrid app using Angular 6. The initial phase involved converting all controllers/directives into an AngularJS component. Subsequently, I created a new Angular 6 project skele ...

Transform the JSON structure with the power of JavaScript

Seeking assistance in converting the following array of JSON using either javascript or jquery: [ [{"day1":10,"day2":154,"day3":24,"day4":48,"day5":154,"day6":48,"day7":154,"name":"Packet"}], [{"day1":10,"day2":154,"day3":24,"day4":48,"day5":154,"day6":4 ...

"Implementing a Callback Function when Jquery Countdown Reaches

Implementing this plugin will result in a live countdown displayed on the webpage. I recently reviewed the on.finish callback documentation found on the Official website. The main objective is to hide the span#limit once the timer completes its countdown ...