Utilizing the child element's attribute value in a list to dynamically modify the CSS styling of a div element

I'm struggling with designing a ranking bar that consists of 9 bars. I want the height of the bars to vary, with bar 0 and bar 8 being the longest. However, I am having difficulty manipulating my jQuery selector to change the CSS style of the bars based on the selected option value. Below is my code.

CSS:

 .rating-c .br-widget {
height: 60px;
display: inline;    
}

.rating-c .br-widget a {
display: inline;    
width: 20px;
height: 60px;
float: left;
background-color: #FFFFFF;
margin: 2px;
text-decoration: none;
font-size: 16px;
font-weight: 400;
line-height: 2.2;
text-align: center;
color: #444444;
border: thin solid #b6b6b6;
}
.rating-c .br-widget a.br-active,
.rating-c .br-widget a.br-selected {
background-color: #59a6d6;
color: white;
}

HTML:

        <div class="rating-c">
             <label class="ratingLabel">
                 <select id="rating-c" name="rating">
                      <option value=""></option>
                      <option value="1">4</option>
                      <option value="2">3</option>
                      <option value="3">2</option>
                      <option value="4">1</option>
                      <option value="5">0</option>                            
                      <option value="6">1</option>
                      <option value="7">2</option>
                      <option value="8">3</option>
                      <option value="9">4</option>
                    </select>
                 Price</label>    
            </div>

JavaScript:

$('.rating-c .br-widget a select[name=rating]').each(function(){
            if($(this).attr("value")==="2"){
                $(".rating-c").css("height", "55px");
            }
            if($(this).attr("value")==="3"){
                $(".rating-c .br-widget a").css("height", "50px");
            }
        });

I'm facing issues with getting this code to work properly. Can someone provide assistance? Thank you in advance for your help!

Answer №1

After taking @SterlingArcher's advice, we can implement this.value along with parseInt...

if (parseInt(this.value) === 3) {
    $("anotherThing").css("newKey", "newValue");
};

To clarify, using parseInt converts the value to a number for more accurate comparisons.

Additionally, utilizing this.value accesses the property instead of the attribute. In jQuery, you could achieve this by using $(this).val(), which retrieves the property rather than the value attribute you were previously utilizing.

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

displaying pictures exclusively from Amazon S3 bucket using JavaScript

Considering my situation, I have a large number of images stored in various folders within an Amazon S3 bucket. My goal is to create a slideshow for unregistered users without relying on databases or risking server performance issues due to high traffic. I ...

A guide on integrating variables into a MySQL table using PHP

I am currently working on a project where users should be able to select their schedule. Here is the code that I have written so far: <?php //if form has been submitted process it if(isset($_POST['submit'])){ $servername = "localhost"; ...

I cannot locate the dropdown list anywhere

As a beginner in html and css, I decided to follow a tutorial on youtube. The tutorial focuses on creating a navigation bar with dropdown menus using html and css. I wanted the names Ria, Kezia, and Gelia to be displayed when hovering my mouse over the Su ...

I want to set a single background image for all slides in fullPage.js. How can I achieve this

I am attempting to replicate a similar effect as shown in this example: The demonstration above utilizes the fullPage.js plugin. You may have noticed how the background image remains consistent while navigating through different sections. I have searched ...

Ways to verify the presence of users in the Database

I have successfully retrieved the data with the code below, but I am encountering issues with my script's if and else statements. Any tips or advice on how to improve this functionality? server.post('/like', (req, res,next) => { var ...

I'm receiving the error message "app.get is not a function" when using Express.js. What could be

Having trouble understanding why I am getting an error: app.get is not a function in the upload.js file with the provided code snippet. In my index.js file, I have set up everything and exported my app using module.exports = app. I have also used app.set( ...

What is the process for removing an added message using jQuery after it has been appended by clicking the same button?

https://i.stack.imgur.com/YsmKZ.pnghttps://i.stack.imgur.com/dW2lo.pngI have searched extensively through previously asked questions without success. My goal is to remove the previous appended message when the submit button is clicked again. This functiona ...

Is it possible in Angular.js to limit the visibility of a service to only one module or to a specific group of modules?

When working with Angular.js, the services declared on a module are typically accessible to all other modules. However, is there a way to restrict the visibility of a service to only one specific module or a selected group of modules? I have some service ...

objects bound to knockout binding effects

I have been struggling to understand why the binding is not working as expected for the ‘(not working binding on click)’ in the HTML section. I have a basic list of Players, and when I click on one of them, the bound name should change at the bottom of ...

Template file for the contact form 7 plugin in Wordpress

I'm currently utilizing the Contact Form 7 plugin on my Wordpress website and I'm curious about which template it directs to when I enter mysite.com/contact/ into the browser. I am interested in making some edits to the template file, but I am un ...

Value of MySQL in a web form

Currently in my PHP code, I have the following: echo '<input type="email" name="email" value=''; I am looking to automatically populate the value with a data from a MySQL row (let's say ['name']), but I am encountering syn ...

Scraping the web with Python: Selenium HTML elements may differ from what is shown in the inspect tool

In my current academic project, I am facing an issue with scraping news articles from websites. The problem arises when parsing HTML code in Python because the code obtained from the page source is different from what is shown in the Inspect Element tool. ...

Issues arise when trying to manage HTML received as a response from a server in plain text

I have a scenario where I am dynamically generating an HTML table on the server side using Java and then sending it to the client as JSON data. The response looks something like this: <table class="table"></table><thead class="thead-dark"&g ...

The concept of navigation and passing parameters in Angular.js

Attempting to customize the standard user module of MeanJS, I added a new route: state('users', { url: '/users/:username', templateUrl: 'modules/users/views/view-profile.client.view.html' }); ...

Modify the size of images retrieved from the Twitch API

I have a request to the Twitch API to retrieve a list of top games and show their box art, but I'm facing an issue where the image will only display if I adjust the width and height values in the provided link. Is there a way to modify these values wi ...

Tips for showcasing a search bar on Google search results

While browsing in Google, I came across websites that have a search bar displayed after their initial search result. This functionality allows users to easily search within the website as shown in the image below. I am intrigued and wondering how this can ...

Use the zoom feature on D3 to enhance two graphs in an HTML document

I have been experimenting with d3 libraries lately and came across http://bl.ocks.org/jroetman/9b4c0599a4996edef0ab. I successfully used it to draw a graph based on data from a tsv file and enable zoom in and out functionality, which worked well for me. Ho ...

Directive for displaying multiple rows in an Angular table using material design

I am attempting to create a dynamic datatable with expandable rows using mat-table from the material angular 2 framework. Each row has the capability of containing subrows. The data for my rows is structured as an object that may also include other sub-ob ...

"Unlocking the power of Bootstrap modals in Django

Using Django, I have a loop of div elements. When I click on a div, I want a modal to be displayed. Here is my HTML code: {% for object in theobjects %} <div class="row" style="margin-top:0.5%;"> <div name="traitement" <!-- onclic ...

In search of a solution to ensure equal width for all items in a 2x2 grid

I have a CSS grid with two rows and two columns (refer to the code snippet). Is there a way to make all the items in the grid maintain the same width without specifying it individually? Are there any css-grid properties that can ensure consistent widths ...