JS function to change links like <a href="something.wav">sound</a> so that they play when clicked
✓ Published0🌍 Public
Aamundo
Last edited Mar 19, 2014
Created on Mar 19, 2014
This example shows a JavaScript function that converts links to .wav audio files on a page into click-to-play controls, so users can listen without leaving the page or losing the link’s context. The code selects all anchor elements whose `href` ends with `wav` using `document.querySelectorAll`, then creates a new `Audio` object for each link and assigns the link’s URL as the audio source. It attaches a `click` event listener that prevents the default navigation behavior and calls `audio.play()` to start playback. The approach uses the native Web Audio API and DOM event handling, with no external libraries.
AI-generated description