0

How to change css style for the preview page dynamically using jquery.

two dropdown with right side preview page, dropdown loaded with color, based on the selection, preview page css (bg color, font color) should change,

We have tried with below snippets, bg color is working, but font color not working.

//bg_color: this variable contain the dynamic BG color selection values
//font_color: for font color.
$("#web_preview_right_div").css({'background-color':bg_color});
$("#web_preview_right_div").css({'color':font_color});

in inspect element,

when i change dropdown, below color:rgb(255,128,0) code changing, but font color not applying.

also i added important, but it is not working.

background-color: rgb(245, 208, 169); color: rgb(255, 128, 0);

9
  • 2
    where is your "below snippet" ? Commented Mar 18, 2014 at 13:05
  • sorry just updated now Commented Mar 18, 2014 at 13:06
  • you can try .css method .. like $('something').css("color",'#333'); Commented Mar 18, 2014 at 13:06
  • this not working @MsiSaurovh Commented Mar 18, 2014 at 13:07
  • Not need to use object in .css() if you are using a single property Commented Mar 18, 2014 at 13:08

4 Answers 4

1

It seems that you have missed quotes in color value.

try like this:

$("#web_preview_right_div").css({
                                'background-color': 'black',
                                'color':'red'
                                });

demo

Sign up to request clarification or add additional context in comments.

Comments

1

No need of using object in css if you are using single property.

 $("#web_preview_right_div").css('background-color',bg_color);

However you selector is same, so you can combine these two statements in one

    var font_color="red";
    $("#web_preview_right_div").css({
                                    'background-color':bg_color,
                                    'color':font_color
                                    });

Comments

0

You can do that in 1 row

$("#web_preview_right_div").css({'background-color':bg_color, 'color':font_color});

Like with json

Comments

0

.parentdiv label { color:#000000; word-warp:break-word;}

my jquery snippet unable to over ride the above css color:#000000, so i just remove the color property, now problem solved, thanks to every one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.