A guide on customizing Check Box borders using Dart

Is there a way to dynamically change the border color of a custom checkbox when an event occurs? Here is the HTML code snippet:

      <input id='B12' type='checkbox' class='checkbox' checked='checked'>
        <label for='B12'>B12&nbsp;&nbsp;</label>
      <input id='B10' type='checkbox' class='checkbox' checked='checked'>
        <label for='B10'>B10&nbsp;&nbsp;</label>
      <input id='B8' type='checkbox' class='checkbox' checked='checked'>
        <label for='B8'>B8&nbsp;&nbsp;&nbsp;</label>
      <input id='BBW' type='checkbox' class='checkbox' checked='checked'>
        <label for='BBW'>Wide&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>

The following CSS defines the styles for the checkboxes and labels:

input[type="checkbox"] {
  display: none;
}

input[type="checkbox"]+label:before {
  outline: 0;
  border: 2px solid #F8F8E0;
  content: url(resources/CheckBoxUnchecked.png);
  display: inline-block;
  font: 24px/1em sans-serif;
  height: 24px;
  margin: 0 .25em 0 0;
  padding: 0;
  vertical-align: top;
  width: 24px;
}

input[type="checkbox"]:checked+label:before {
  border: 2px solid #077313;
  background: #00ff00;
  content: url(resources/CheckBoxOK.png); /* icon */
  text-align: center;
}

input[type="checkbox"]:checked+label:after {
  font-weight: bold;
}

I am using Dart to loop through a list of checkboxes and want to change the border color to red if they are checked. The current code I have tried does not work. How can I properly access and modify the border color?

Here is the Dart code snippet:

final checkBoxes = querySelectorAll('[class=checkbox]');
// later
for(; whichImage < 4; whichImage++){
  if(checkBoxes[whichImage].checked) {
    imageElement.src = imageList[whichImage];
    // checkBoxes[whichImage].border = '1px solid red';
    break;
}

Answer №1

UPDATE

For more information, please refer to this helpful guide on styling checkboxes using CSS: How to style checkbox using CSS?

original response

To apply style properties directly:

checkBoxes[whichImage].style  
    //..border = '1px solid red'; // either this way or
  ..borderWidth = '1px'
  ..borderStyle = 'solid'
  ..borderColor = 'red';

It is generally recommended to use external stylesheets as shown by @sunglim

Answer №2

Implement some Css styles.

.SelectedStyle {
  border: 1px solid blue;
}

On the JavaScript side,

   ...

   document.querySelector('.selectedElement').classList.add('SelectedStyle');

   ...

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

Can you provide me with instructions on how to change the background image?

Having trouble with the CSS code I wrote for a background-image. It's not showing up when I set it in my CSS stylesheet. I tested it and found that it only works when written in the body... <body background="Tokyo.png"> ...but not in the styl ...

JavaScript for validating dimension text input has unique functionalities

I am looking for guidance on validating an ASP textbox using JavaScript. My goal is to validate a user's input in the format of 4-1/2, 80-1/2, 6/8, or simply 5. Only these types of patterns should be allowed, and each input must contain only one numbe ...

Table created by Javascript is malfunctioning

Is there an obvious mistake to be found? Why isn't the Javascript generated table from the showResults function displaying on my HTML page? This issue always arises when I need to include a large number of literal values... I would also welcome feedba ...

Align three divs with three columns in the horizontal center

I am facing a challenge where I need to perfectly center 3 col3 divs in a row. Despite the calculation showing 1.5, I am unsure of the proper method to overcome this hurdle. <div class="row"> <div class="col-md-offset-2 col-md-3" style="height: ...

Can a Django ID be transferred to a jQuery function within an HTML element?

In my current setup, I have a series of blog posts being displayed using a for loop. Each post includes a comment form with a send button underneath it. To differentiate each post, I am including the {{post.id}} within the id attribute of the button elemen ...

Evaluate the user's answers to a database using a SQLite 3 C++ Quiz

Currently, I am in the process of writing a C++ program that utilizes SQLite. The main aim is to enable users to specify their preferred hotel room options. Subsequently, the program compares these user selections with the information stored in a database. ...

Kendo checkbox toggle issue with switching between true and false states is not functioning correctly

How can I make a button appear when one or more checkboxes are clicked? Currently, the toggle function only activates when I select one checkbox, and then deactivates upon selecting another. Any guidance on improving this functionality would be greatly app ...

AngularJS - A Guide to Detecting Window Resize and Orientation Changes in Landscape and Portrait Modes

I have attempted various suggestions from Stack Overflow, but none of them have been successful. Essentially, I am seeking to update (re-render) a custom directive whenever the window size changes. This is my code: angular.module('dynamicSlideBox&ap ...

Utilizing Flexbox for Spacing

When utilizing flex containers, is it considered safe and acceptable to apply margin-top, margin-bottom, margin-left, margin-right, and padding to create a little space between elements or shift them to the left or right? Or is it more advisable to use f ...

``Is there a way to display fetched data in a horizontal layout instead of vertical using angularJS?

I'm in need of generating reports using AngularJS and PHP. Desired Output: Spec_ID Bot_Name Color Colorno Screen AN/SN/18 750ML POCO PESCA ROTATION 1 Light Buff Dark Buff Red P ...

Node.js provides a straightforward way to decode HTML code

Can strings with HTML-encoded characters like &#39;, &amp;, etc., be converted into plain character strings without using multiple str.replace(/&#39;/g, "'") statements? ...

Tips on causing a div to overflow instead of wrapping onto a new line

Are you looking to design a slider with 3 image containers all in the same row, where the third one overflows instead of wrapping to a new line? Here is an example: Desired Design: https://i.stack.imgur.com/dKyEg.png Current State: https://i.stack.imgu ...

What are some ways to customize text using Font-Awesome?

<i class="fa fa-envelope fa-lg"> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aad8c5c8ccd8cbc4eacdc7cbc3c84ac9fbccdbdb">[email protected]</a> </i> I need assistance with changing the font type f ...

scrollable header within the confines of the container

I have been trying to find a solution for my scrolling issue, but I just can't seem to get it right. I want the content within a div to scroll inside its container without affecting the header. Here's the updated JSFiddle link with the jQuery cod ...

Why is there an excessive amount of white space on my Reactjs page?

This webpage (page URL -) displays well without any white space between two images when viewed on a laptop. However, when accessed on a mobile device, it appears to be taking up too much space as shown in the image below. Image of webpage on laptop- lapto ...

Webpage not resizing when WebView orientation changes

While developing my android app, I encountered an issue with the WebView. When I am at the very top of the WebView and switch my phone to landscape mode, the webpage does not resize properly to fit the screen. It only takes up half of the screen. However, ...

Using jQuery to establish a canvas element and define its dimensions by adjusting its width and height attributes

My attempt at using jQuery to create a canvas element was not quite as expected. Here is the code I tried: var newCanvas = $('<canvas/>',{'width':100,'height':200,'class':'radHuh'}); $(body).append(n ...

Web design featuring an aesthetic reminiscent of an open folder on an iPhone

I'm struggling a bit and could really use some assistance. I've been searching for a long time but can't seem to figure out how to create an iPhone folder-like design for the web. The design should have that "slide out" effect when you click ...

The use of non-breaking space symbol ( ) does not function properly in Weblogic 14

After upgrading from Weblogic 12 to Weblogic 14 Server, I encountered a change in behavior. Previous Status Everything was functioning properly before the update. When requesting an html page with &nbsp; whitespaces, the server would include these spa ...

Incorporating personalized CSS and JavaScript into Shopify

Currently, my project involves integrating vertical tabs into a Shopify page that is utilizing the 'Atlantic' theme. Since this particular theme doesn't come with vertical tabs built-in, I have incorporated external JS and CSS files known as ...