0

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');
    }
}
Regent
  • 5,142
  • 3
  • 21
  • 35

1 Answers1

1

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/

Richi
  • 100
  • 8
  • would that also work if i wanted to change margin and what not do i jsut replace backgroundcolor with margin for eg – Abdel hakeem Feb 13 '15 at 12:07
  • Sure you can, because it's an html domelement. give it a try to define in in in such a program like dreamweaver. var x = document.getElementById ("id"); x.style. You will see a list of all CSS styles that you can set after x.style. – Richi Feb 16 '15 at 10:13