문제

I am making a firefox extension, and I would like the background-color of my toolbarbutton to change in response to a message in an xmlhttp request. This is what I have, but it doesn't work:

    if(x.section == 1)
    {
        var element = document.querySelector('#custom-button-1');
        element.style.backgroundColor = green;
    }

    if(x.section == 0)
    {
        var element = document.querySelector('#custom-button-1');
        element.style.backgroundColor = red;
    }

I know that the problem isn't x.section because did some testing with alerts. Do you know what I'm doing wrong?

도움이 되었습니까?

해결책

You need to change the color values to strings (with quotes):

element.style.backgroundColor = 'red';

or

element.style.backgroundColor = "red";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top