Worldprogram
Worldprogram

Reputation: 5

Is it possible to change inner css from java script?

We have jquery menu in application, and on selecting of particular element; its background color gets change.

Color is changing according to css. We are designing "Theme" and are trying to change color of css dynamically using Javascript, so that on selecting menu; its color will be changed. But, we are not getting well way to do it.

Following is the css: -

.mmenu li.mmenu-selected > a
{
    background: #1971AA;
    color:#FFFFFF;
    font-weight: normal;
}

Upvotes: 1

Views: 1099

Answers (2)

Siamak Ferdos
Siamak Ferdos

Reputation: 3299

Try css method:

$(".mmenu li.mmenu-selected > a").css({"background": "#1971AA", "color":"#FFFFFF"});

Upvotes: 0

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167240

If you have a fixed number of values for the background, then use classes like this:

.theme1 .mmenu li.mmenu-selected > a {background-color: #f99;}
.theme2 .mmenu li.mmenu-selected > a {background-color: #ff9;}
.theme3 .mmenu li.mmenu-selected > a {background-color: #fff;}

If not, use inline styles, targetting the parent and giving an inherit:

$(".mmenu").css("background-color", "#ff9");

And in the CSS:

.mmenu li.mmenu-selected > a {background-color: inherit;}

Upvotes: 1

Related Questions