PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Unsolved

adding sound effect when a mouse button is clicked

mohanad-raheem

Jan 13th, 2020 06:56 PM

hi total beginner here what is the code for playing a sound effect when a mouse button is clicked i mean even when i click on empty space with no buttons or any elemnt,and where should the code go head body? thanks

bobbyiliev

Sep 27th, 2022 07:38 AM

Hi there,

I am just following up on some old unanswered questions on the site.

Here is a quick snippet to do that:

<!doctype html>
<html>
  <head>
    <title>Audio</title>
  </head>
  <body>

    <script>
      function play() {
        var audio = document.getElementById("audio");
        audio.play();
      }
    </script>

    <input type="number" min="10" max="100" onclick="play()">
    <audio id="audio" src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"></audio>

  </body>
</html

Best,

Bobby