lundi 25 juillet 2016

JavaScript; Background Color change and change back w/ same input

I made this code, but it wont work. Would be nice if some one can help me. :)

I've tried many things already, but it always didn't worked.

I want it to be so that you press the button and the background gets light, when you press it again it goes back to the origin.

<html>
<head>
    <title>test</title>
    <style>
    .darkerBG {
        background: #282828;
    }
    .lighterBG {
        background: white;
    }
    </style>
</head>
<body class="darkerBG" id="bdbackground">

<script language="javascript" type="text/javascript">
function changeColor() 
{
    var bdBackground = document.getElementById('bdbackground').class;

    if (document.getElementById('bdbackground').class == 'darkerBG')
    {
        document.getElementById('bdbackground').class == 'lighterBG';
    } else if (document.getElementById('bdbackground').class == 'lighterBG')
    {
        document.getElementById('bdbackground').class = 'darkerBG';
    }
}
</script>

<input type="button" class="button" value="test" onclick="changeColor()">

</body>
</html>

Aucun commentaire:

Enregistrer un commentaire