简体   繁体   中英

jQuery not changing element background-color

I am using

$(function () {

var one = $('h1');
var two = $('#mainNav img');

if (one.css('color') ==='rgb(12,74,164)') 
{
    two.css('background-color', '#6e6C80');
};

});

to check the if the color of a certain element is the needed one and then change the color of another element. It has no effect. I found that the color I'm checking for needs to be converted to rgb but it doesn't help. What am I missing?

you missed the spaces in RGB

$(function () {

var one = $('h1');
var two = $('#mainNav img');

if (one.css('color') ==='rgb(12, 74, 164)') 
{
    two.css('background-color', '#6e6C80');
};

});

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