jQuery - remove background-color when an element is visible
Asked Answered
E

3

17

I would like to remove the background-color (only the background-color) of the menu once another element is visible. I wrote this code, but it doesn't work - anybody can help?

$(function() {
if($("#wrapperHome").is(":visible")) {
    $("#menu a").css({ "background-color", "black" });  
}
});

The menu has this background style sheet information.

background:url(img/official/menu.png) center center no-repeat #f2f2f7;
Ehf answered 18/11, 2013 at 18:53 Comment(1)
$("#menu a").css({ "background-color" : "transparent" });Sochor
G
34

I believe you want something like this...

$("#menu a").css("background-color", ""); 

Setting the background-color to "" essentially removes the styling, removing the color.

Gonorrhea answered 18/11, 2013 at 19:0 Comment(0)
V
3

Use : not , when doing key/val CSS changes:

$("#menu a").css({ "background-color" : "black" }); 

Or since it's one value:

$("#menu a").css("background-color", "black"); 
Velites answered 18/11, 2013 at 18:56 Comment(0)
C
0

You should move the style into the css for your site. This avoids having css littered through out your js and you can then re-use it.

.selected-menu-item{ // or what ever it is that has a black background
  background-color: black;
}

Then in your jquery:

$("#menu a").toggleClass("selected-menu-item");
Cicero answered 18/11, 2013 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.