I am having trouble changing the background color of a v-card element using getElementById

Creating a web page for a blood bank involves storing blood group information, quantities, and donor lists in an array of cards. However, there seems to be an issue with changing the background color of the donor blood group cards upon selection using JavaScript. The desired light green color change is not happening, and it's challenging to pinpoint the error in the code. Are there any alternative methods to achieve the card color change?

 <v-card>
            <v-container fluid grid-list-md>
              <v-layout row wrap>
                **<v-flex v-for="card in cards" :key="card.blood_group">
                  <v-card class="black--text" height="120px" width="220px" :id="card.blood_group" style="background-color:lightgray">**
                    <v-flex xs12>

                      <v-card-title>
                        <h2 class="justify-center">{{ card.blood_group }}</h2>
                      </v-card-title>
                    </v-flex>
                  </v-card>
                  <v-flex>
                    <v-layout column justify-space-between fill-height>
                      <v-card class="black--text" width="220px" color="grey lighten-2">
                        <v-divider></v-divider>
                        <v-card-text>
                          {{ card.quantity }}</v-card-text>
                      </v-card>
                    </v-layout>
                  </v-flex>
                </v-flex>
              </v-layout>
            </v-container>
            <v-layout justify-center xs12 sm3 md3 row wrap>
              <v-layout column wrap>
                <v-flex xs12 sm5 md5 d-flex offset-sm3>
                  **<v-autocomplete v-model="select" :items="cards" label="Blood required" item-text="blood_group"
                    required @change="eligibleDonors"></v-autocomplete>**
                </v-flex>
                <v-flex xs12 sm6 md4 offset-sm3>
                  <v-text-field v-model="bottles" label="Number of bottles" readonly></v-text-field>
                </v-flex>
              </v-layout>
              <v-layout column wrap>
                <v-flex xs12 sm6 offset-sm3 padding-a-3>
                  <v-card height="300px" width="450px" style="border: black 3px">
                  </v-card>
                  <p style="text-align: center"> Bucket</p>
                </v-flex>
              </v-layout>


            </v-layout>
          </v-card>    <script>

        new Vue({
          el: '#app',
          data: {
            cards: [
              { blood_group: 'A+', quantity: 3, recieve_from: ['A+', 'A-', 'O+', 'O-'] },
              { blood_group: 'B+', quantity: 8, recieve_from: ['B+', 'B-', 'O+', 'O-'] },
              { blood_group: 'O+', quantity: 2, recieve_from: ['O+', 'O-'] },
              { blood_group: 'AB+', quantity: 5, recieve_from: ['A+', 'A-', 'O+', 'O-', 'AB+', 'B+', 'B-', 'AB-'] },
              { blood_group: 'A-', quantity: 9, recieve_from: ['A-', 'O-'] },
              { blood_group: 'B-', quantity: 6, recieve_from: ['B-', 'O-'] },
              { blood_group: 'O-', quantity: 8, recieve_from: ['O-'] },
              { blood_group: 'AB-', quantity: 3, recieve_from: ['AB-', 'A-', 'B-', 'O-'] }
            ],
            select: '',
            bottles: '',
            card_select: ''
          },
          methods: {
            eligibleDonors(event) {

              for (let i = 0; i < this.cards.length; i++) {
                if (this.select == this.cards[i].blood_group) {
                  var selection = i;
                  break;
                }
              }
              for (let i = 0; i < this.cards[selection].recieve_from.length; i++) {
                this.card_select = this.cards[selection].recieve_from[i]
                console.log("eligible blood group: " + this.card_select)
                **document.getElementById(this.card_select).style.backgroundColor = "green"**
                console.log(document.getElementById(this.card_select).style.backgroundColor)
              }
            }
          }
        })
      </script>

Answer №1

To achieve this, a helpful technique is to include important in order to supersede vuetify styles.

demonstration

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

difficulties retrieving information with $http.jsonp

Here is the code snippet that I am working with: var url = 'http://someURL?arg1=test&arg2=test&callback=JSON_CALLBACK'; $http.jsonp(url) .success(function(data){ console.log(data.found); }); Despite receiving a status code of 200 o ...

Validating checkboxes in a jQuery DataTable using JavaScript

I am working with a table that is connected to a JQuery datatable. <table id="grid1"> <thead> <tr> <th>Name</th> <th>View</th> <th>Modify</th> </tr> </thead> </ta ...

Send PHP data through AJAX and retrieve it on a different PHP page

I need to send a variable through an AJAX URL to another PHP page and retrieve it using: $id=$_GET['id']; Here's an example where the value is passed, for instance $id=6. <a id="pageid" href="ifsc-bank.php?id=<?=$id?>"><im ...

When encountering an error in Laravel Vue related to deleting `␍`, it is possible that using the `--fix` option could provide a potential solution to the issue

When running 'npm run watch', I encountered the following error message: 181 problems (181 errors, 0 warnings) 181 errors and 0 warnings potentially fixable with the --fix option. @ ./resources/js/backend/router/index.js 15:0-41 160:2 ...

Prevent closure of Bootstrap offcanvas on backdrop click in a Blazor .NET application

Trying to implement an offcanvas window form and ensuring it stays open only when the user clicks the close button. Following client requirements, I need to call the offcanvas window via C# with IJSRuntime injection instead of directly from HTML. Operatin ...

Issue with navigation links on HTML website not functioning as expected

I would like the dropdown menu items to be clickable. For example: Menu item: Services Sub items: - branding } These already have working links - marketing } However, when I try to replace '#' with a link for Services, it d ...

Vue.js failing to update when object property changes

<v-container class="text-center hyp-container pa-4"> <v-row> <button @click="toggleForm">Create new target</button> </v-row> <v-row> <v-dialog v-model="showConfirmDelet ...

What is the procedure for assigning an element's background-color to match its class name?

Is there a way to use jQuery to make the background color of a span element match its class? $(function() { $("span").css("background-color") }); span { display: inline-block; width: 5px; height: 5px; border: solid #0a0a0a 1px; } <script src= ...

Using the TIMESTAMP data type in PostgreSQL and getting the most out of it

After saving a Luxon datetime value in a TIMESTAMP(3) type column in a postgres database, I encountered difficulty using it for various operations like converting time zones. Despite creating the object with the code snippet below: const { DateTime } = req ...

What are the steps to clear a client's local cache after updating my website?

Is there a simple way to clear the cache of all players who have previously played my game? The game stats are stored in local storage, and some players experienced bugs when the stats were incorrect. This outdated data is now affecting the updated stats ...

Issue arising with data exchange between components using data service in Angular 5

Utilizing data service to share information between components has presented a challenge for me. References: Angular: Updating UI from child component to parent component Methods for Sharing Data Between Angular Components Despite attempting the logic o ...

How to make Angular resolver and component share an injected service?

In my products list component, I have a table displaying various products. Since there is a considerable amount of data, I implemented a resolver to prevent the user from being directed to the page until all the data is loaded. The resolver currently utili ...

Modification of text within a text field via a context menu Chrome Extension

Currently, I am embarking on my first endeavor to create a Chrome extension. My goal is to develop a feature where users can select text within a text field on a website using their mouse and have the ability to modify it by clicking on a context menu. Be ...

Issue with collecting data in Meteor Collection

After making some edits to another file and increasing the complexity of my application, a tracker function that was previously working fine is now experiencing issues. It is no longer returning any data for vrLoan fundingData This is a snippet of my c ...

javascript loop that runs on every second element only

After completing an ajax query, the following JavaScript code is executed. All of my images are named "pic". <script type="text/javascript> function done() { var e = document.getElementsByName("pic"); alert(e.length); for (var i = 0; ...

Automatic File refresh in Javascript without page reload

My webpage includes a javascript file that is called in the head tags of the document. I need this javascript file to reload every 30 seconds. In my research, I found issues with pulling a locally stored copy of the file and potential cross-browser compat ...

Load high-quality gif picture in advance

My task involves a lengthy process that takes several seconds to complete. To make the waiting time more bearable, I have implemented an animated loading page. <style> .modal_gif { display: none; position: fixed; z-index: ...

Why is it that one function does not hold off on execution until Promise.all() is resolved in another function?

I am currently working on a form that allows users to upload files seamlessly. <form @submit.prevent="sendForm" enctype="multipart/form-data"> <input multiple ref="PostFiles" name="PostFiles" type="file" @change="selectFile('add')"> ...

Issues with the functionality of AJAX response values

I have been attempting to enhance a feed by adding new content when a user reaches the bottom of the page, but I am encountering issues with retrieving the content. Below is the jQuery/Javascript code I am using: $(window).scroll(function(){ if($( ...

Browse the string on the web browser

Is there a way for me to continuously read and capture a string as it is being written in the browser, retrieving its value every 5 seconds? I need to be able to monitor the changing value while it is being input. In PHP, I have the following code snippet ...