Abdel hakeem
Abdel hakeem

Reputation: 21

Change css background color in my function

I have this code to change my buttons inner HTML when they are clicked. I also want to change the CSS background color when button is clicked, but I couldn't get it to work.

<button id="showTop" class="menubtn" >Show Menu</button>

var menuTop = document.getElementById('cbp-spmenu-s3'),
    showTop = document.getElementById('showTop'),
    body = document.body;

showTop.onclick = function() {
    if (showTop.innerHTML == 'Show Menu') {
        showTop.innerHTML = 'Hide Menu';
    } else {
        showTop.innerHTML = 'Show Menu';
    };

    classie.toggle(this, 'active1');
    classie.toggle(menuTop, 'cbp-spmenu-open');
    disableOther('showTop');
};

function disableOther(button) {
    if (button !== 'showTop') {
        classie.toggle(showTop, 'disabled');
    }
}

Upvotes: 0

Views: 436

Answers (1)

Richi
Richi

Reputation: 100

You mean like this?

if (showTop.innerHTML == 'Show Menu') {
    showTop.style.backgroundColor = "blue";
    showTop.innerHTML = 'Hide Menu';
} else {
    showTop.innerHTML = 'Show Menu';
    showTop.style.backgroundColor = "";
};

http://jsfiddle.net/richiwarmen/pcjhsy99/

Upvotes: 1

Related Questions