Keyboard.html:16 Uncaught DOMException: Failed to execute 'querySelector' on 'Document': 'audio[data-key=65]' is not a valid selector

Attempting to make a querySelector that will select html “data-key” elecments as follows:

<! DOCTYPE html>
  <title>yo dog</title>
  <div class-key="65" class="key">

<audio data-key="65" src=""></audio>

<script type="text/javascript">
window.addEventListener('keydown', function(e){
  const audio = document.querySelector(`audio[data-key=${e.keyCode}]`);



When using attribute selectors the value property must be a string:

so simply wrap your value into quotes should fix the issue:


Hope it helps :+1:

Well done. People like you keep civilization moving ahead.