Update CSS using onChange event with an array of values

I'm currently working on an app that allows users to select a color scheme from a dropdown form. The hexidecimal values associated with the selected color scheme successfully populate specific text fields as intended. However, I am facing difficulty in getting the background color of the text field to change according to the selected value.

You can view my fiddle here: http://jsfiddle.net/z4WxP/7/

I have tried various approaches, including adding a class and using CSS append to assign the value, but so far nothing seems to work:

document.getElementsByName('color_body_bg')[0].value = bodyBG[text].css('background-color', value = bodyBG[text]);

Answer №1

  Changing the background color of an element based on a selected option from a dropdown menu.

Here is a link to the code snippet: http://jsfiddle.net/YpJKB/

Answer №2

Insert the following code snippet at the conclusion of the displayColor() function:

  $('.appendSelection').each( function (){
      $(this).css('backgroundColor', $(this).val());
  });

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

Rails 4 not properly executing success function after rendering JSON response

Currently, I am utilizing the jQuery method $.get to retrieve a JSON response from the server. $.get(SITE_EDIT_HOME_URL,{key: key},function(r){ r = JSON.parse(r); console.log(r); }); This is how I handle the request and send back a response: def g ...

Enhancing Javascript Dialog Box with a Touch of Animation

Collaborating with the incredibly talented Mark Eirich has been an amazing experience. We have been working on revamping a JavaScript dialog box together, and Mark has set up something on JSFiddle that will be incredibly beneficial. However, I am seeking a ...

toggle the class on a label that contains a checkbox

Is there a way to use toggleClass to add a class to a label when clicked, even if the label contains a checkbox? Currently, I am having an issue where the class is only added when clicking directly on the checkbox. How can I make it so that the class is ad ...

Create an array that only stores non-zero values in a

I'm looking to initialize a static array with non-sequential values. A traditional method for initializing sequential arrays looks like this: class Foo { public: static const char * name[]; } const char * Foo::name[] = { "Sun", "Moon" }; Ho ...

Error: operand a contains an invalid 'in' statement

After sending a request to the server using jQuery's $.ajax, I am getting back JSON data. $.ajax({ url: 'moreMonth.ajax', data: { startIndex: id }, success: function(data) { $.each(data, function(k, v) { alert(k + ':&ap ...

Do you have any recommendations for a jQuery plugin that can create a sleek horizontal scrolling image gallery?

Recently, I came across the Smooth div scroll plugin developed by Thomas Kahn, and it fits my requirements perfectly. However, I have encountered a bug that seems to be persisting. The issue arises when both mousewheel scroll and touch scroll are enabled s ...

Having an excessive amount of CSS Sprites or none at all can be detrimental to your website's performance

UPDATE: Attempted to adjust the height to 27px as recommended by kennypu, but still facing issues. I am working with a sprite containing multiple icons that I want to extract for navigation purposes. Unfortunately, I'm struggling to properly display ...

Acquiring the applicable CSS for a JavaFX 8 widget

While working on JavaFX styling with CSS, I encountered a challenge in understanding which CSS properties are directly affecting the appearance of a GUI widget. It reminded me of using Firefox web developer tools to inspect elements and view the specific s ...

Concealing spinner controls on HTML Ionic number input

Seeking a foolproof method to conceal spinner buttons on an HTML template for Ionic's number input field. Showcased below is the HTML code that exhibits an input with spinner buttons: <ion-input type='number'></ion-input> The ...

What is the best way to center CSS content such as boxes and text?

As a beginner in CSS tutorials, I am seeking guidance on how to center the entire content in the browser. Below is the CSS code that needs attention. Additionally, there is a screenshot of the current output included for reference. body { background:#E9 ...

Anticipated the start of an array but encountered a string instead on line 1, character

Exploring Java/Android as a beginner, I am attempting to create a class that queries basic REST JSON data from the URL . Here is a sample of the JSON response received: { "cep": "69050-110", "logradouro": "Conjunto Tocantins", "complemento": "", " ...

Insert a division into the table following every row

I'm working with a table that can be found here: https://codepen.io/anon/pen/bjvwOx Whenever I click on a row (for example, the 1st row 'NODE ID 1'), I want the div with the id #divTemplate to appear below that particular row, just like it d ...

Tips for managing a date picker with JavaScript using the Selenium WebDriver

I have been attempting to scrape a travel website using Selenium Webdriver and Python. While I have successfully set the destination (destino) and place of origin (origem), I am encountering difficulties when trying to select a date. I understand that Ja ...

Currently working on enhancing the responsiveness of the login form

I am encountering difficulties while trying to make the page responsive. I've checked my basic code, but something seems off. Could you please take a look at the plnkr link below and give me some feedback on where I might have gone wrong? Here's ...

Display the div only during the printing process

Imagine I have a situation where there is a block of content that I only want to show when printing. It looks something like this: <div id="printOnly"> <b>Title</b> <p> Printing content </p> </div&g ...

Using jQuery to extract a href URL from a div tag with jQuery

Is it possible to extract the href urls from anchor tags within a div tag? <div id="testing"> <a onclick="http://google.com">google</a> <a href="http://facebook.com">facebook</a> <a onclick="http://gmail.com">gmail< ...

How come I am still able to use jQuery's clone(true, true) method even after leaving the function where it was originally called?

When I used jQuery's clone(true,true) method to clone an element and store it in a variable newElem within a function, everything seemed to work fine. However, I noticed that even after exiting the function, the newElem variable (where the clone is st ...

Link the click counter to individual products

Currently utilizing Wordpress I have successfully implemented a jQuery click counter. However, I am now looking to integrate this code into the div of the quick view button as the quick view button do not currently track any view counts. How can I effici ...

How to automatically collapse all opened accordion panes in jQuery when a new one is expanded

I am currently working on implementing an accordion feature that needs to collapse other expanded links when a new one is clicked. I am aware that this functionality is available in the accordion plugin, but I want to avoid adding another library like jQue ...

Discover the secret to automatically calling a function every minute when the page is loaded!

Our team is currently developing a PhoneGap application with 4 pages. We are in need of posting the current latitude and longitude every minute to our server. Fortunately, we are familiar with how to post values to the server as well as how to retrieve the ...