[Solved] Background color change from dropdown using javascript


Here is a solution using jQuery

$(document).ready(function () {

//$("#background").css("background-color",$.cookie("defaultColor"));

    $("#background-change").change(function (event) {
      var color =  $(this).val();
       $("#background").css("background-color",color);

        //$.cookie("defaultColor",color);
    });
});

The code will change the background based on the selected value in the dropdown list.

To set and retrieve cookie using jQuery, you have to use the jQuery Cookie Plugin

Use this code to set cookie

$.cookie("defaultColor",color);

Then use this code to retrieve cookie and set it as the backround color

$("#background").css("background-color",$.cookie("defaultColor"));

Check the Fiddle

2

solved Background color change from dropdown using javascript