Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Steven GoldenFront End Web Development Techdegree Graduate 25,255 Points
Interactive Media Player-Selecting the correct element
Trying to get the value of aria-valuenow:
<span class="mejs__time-total mejs__time-slider" role="slider" tabindex="0" aria-label="Time Slider" aria-valuemin="0" aria-valuemax="59.861333" aria-valuenow="8.180167" aria-valuetext="00:08">
My code is: const videoTimer = document.querySelector('.mejs__time-total[aria-valuenow]'); const videoTime = videoTimer.value;
I get the error in the console: Uncaught TypeError: Cannot read property 'value' of null
I am not sure why I am having trouble with selecting elementmediaplayer.js element.
Steven Parker225,664 Points
The cause of that error is unclear.
The message would seem to indicate that the querySelector call was unable to find the target element, but the selector seems to match the
span in your HTML snippet. Perhaps it would help if you show the complete code or provide a link to a snapshot of your workspace.
But even without the error, I'm not sure this would do what you want. To get the value of aria-valuenow, try this:
const videoTime = videoTimer.getAttribute("aria-valuenow");