1)
- My goal is to change the style of a sound button after pushing a key ("a" in that case).
- After pushing "a" key, no style changement is made although I have built a CSS style linked to the event (by the class selector .button1) and there is sound. The function click() is working properly after pushing "a" (because: sound) but the style is not changing.
- No error message.
2)
- I have tried several things: .button1:active; .button:hover; put style within the JavaScript lines; creating a class for each event by adding classList.add('MyClass'); change the CSS selector (. or #).
3)
HTML file:
<button onclick="play1()" id="button1" class="button button1">A</button>
<script>
document.addEventListener("keydown", logKey);
function logKey(){
if (event.keyCode === 65) {
document.getElementById("button1").click();
}
}
</script>
CSS file:
.button1 {
left: 400;
bottom: 400;
position: fixed;
margin: 0 auto;
height: 120px;
width: 120px;
background-color: rgba(70, 96, 150, 0.6);
text-align: center;
font-size: 16px;
border-style: solid;
border-color: black;
border-width: 4px;
border-radius: 20px;
}
.button1:active {
background-color: #4CAF50;
color: white;
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
height: 122px;
width: 122px;
}
Thanks. PS: I do not use libraries/frameworks.