0

dreamweaver screen cap

Okay I'm working on project and im on number 2, i have and issue with the toggling and I can't seem to get that too work.

document.getElementsByClassName("buttons")[1].onmousedown=
    function(){
        colorchange();
    };
}
function colorchange() {

    /*var background = function blue(){document.getElementsByClassName("buttons")[1].style.border;*/
    if (getElementsByClassName("buttons")[1].style.border == "5px #c90 solid") {
        document.getElementsByClassName("buttons")[1].style.border="5px blue solid";
    } else {
        if (getElementsByClassName("buttons")[1] == "5px blue solid") {
        document.getElementsByClassName("buttons")[1].style.background = "5px #c90 solid";
    }

}
}
Hot Java
  • 409
  • 5
  • 16

2 Answers2

0

The line where you do:

if (getElementsByClassName("buttons")[1] == "5px blue solid")

Should be:

if (getElementsByClassName("buttons")[1].style.border == "5px solid blue")
holalluis
  • 108
  • 2
  • 10
  • yes that code line was missing, I probably forgot to re add it while playing with the code. but it still will not fire. – Hot Java Mar 03 '15 at 00:46
0

Here is a way to do it:

window.onload = init;
var stateTwo = false, colorsThree = ['#cc9900','#1e3a03','#611790'];

function init(){
    var btns = document.getElementsByClassName("buttons");
    btns[0].onmousedown = btns[0].onmouseup = funcOne;
    btns[1].onclick = funcTwo;
    btns[2].onclick = funcThree;
}

function funcOne(e){
    this.style.background = ( e.type == 'mouseup' )? '#336600' : '#bd270a';
}

function funcTwo(e){
    stateTwo = !stateTwo;
    this.style.borderColor = stateTwo ? '#0c1583' : '#cc9900';
}

function funcThree(){
    colorsThree.push( colorsThree.shift() );
    this.style.borderColor = colorsThree[0];
}

JS Fiddle Demo

blex
  • 24,941
  • 5
  • 39
  • 72
  • not sure if I get this one. seems to be using jquery? which I can't use in this. – Hot Java Mar 03 '15 at 01:14
  • @molliminous No jQuery, just pure JS. What you might think is jQuery (`variable = condition ? valueA : valueB`) is actually a [shorthand version of an `if` statement](http://stackoverflow.com/questions/18269286/shorthand-for-if-else-statement). – blex Mar 03 '15 at 01:17
  • @molliminous [**Here is a version**](http://jsfiddle.net/3p998gxk/1/) with full `if` statements. – blex Mar 03 '15 at 01:25
  • I see, I looked over and it works perfectly fine, but I'm not sure I understand why it works. There is a few things used that im not sure why they work. but I'll look it up on my own. Thank you – Hot Java Mar 03 '15 at 02:12