<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Документ без названия</title>
<style>
#element {
color: green;
width: 50px;
height: 50px;
border: 1px solid #000000;
}
#element2 {
width: 50px;
height: 50px;
border: 1px solid #1065D8;
}
.class {
background-color: red;
width: 100px;
height: 100px;
}
.class2 {
background-color: green;
width: 100px;
height: 100px;
border-color: #9d9d9d;
}
#button1 {
background: rgba(35, 110, 179, 1.00);
color: rgba(21, 227, 211, 1.00)
}
</style>
</head>
<body>
<button id="button1">батон</button>
<div id="element"></div>
<div id="element2"></div>
<script type="text/javascript">
window.onload = function () {
document.getElementById("button1").onclick = function () {
var el = document.getElementById("element");
var el2 = document.getElementById("element2");
el.className = el.className == 'class' ? '' : 'class';
el2.className = el2.className == 'class2' ? '' : 'class2';
};
};
</script>
</body>
</html>
так работает