简体   繁体   中英

addClass(“test”) doesn't work - but css(“background”,“red”) does

Anyone know why?

Here's the JS:

$(".screenshots .tab1").hover(function() {
    $(".section1").addClass("test");
        }, function() {
    $(".section1").removeClass("test");
        });
    });

And the CSS:

.test {
    background: black;
    border: 1px solid #ffb75b;
    background-color: #fffadb;
    } 

Maybe there is a css entry that overrules yours. Try this:

background-color: #fffadb !important;

Maybe it is just a copy and paste error but you have a }); to much. Should be:

$(".screenshots .tab1").hover(function() {
    $(".section1").addClass("test");
}, function() {
    $(".section1").removeClass("test");
});

See a live example: http://jsfiddle.net/wmD4E/

Of course background: black will have no effect because background-color: #fffadb; overwrites it.

I think it is because you have an extra }); at the end of your JS code. see working example here http://jsbin.com/adeye4/edit

Try specifying background once:

.test {
    border: 1px solid #ffb75b;
    background-color: #fffadb;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM