How to assign a different sound to different divs using the solution Gary gave me below?

Hello Experts ( including Gary. ;) )

Using Gary's solution to add sound to a div on a rollover. How do I use this method applying different sound for different divs. In example. DIV Apple - sound is a crunch : DIV Banana - a slip sound..etc?

Is it as simple as changing the id name "hoverme" to something to else like a"apple" and creating another version of "audio_test" an d call it "apple_test"?

And secondly, how do I apply a sound to a like a regular "close button"?

<audio id="audio_test">
    <source src="http://demo.codesamplez.com/audio/pitbull.mp3" type="audio/mpeg">
        <source src="http://demo.codesamplez.com/audio/music.ogg" type="audio/ogg">
</audio>
<div id="hoverme">Hover me</div>

Open in new window


$("#hoverme").hover(function () {
    $("#audio_test").trigger('play');
}, function () {
    $("#audio_test").trigger('pause');
})

Open in new window



Thank you in advance.
colonelblueAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Create your audio elements giving each one a different ID e.g.
<audio id="audio_test1">
    <source src="http://demo.codesamplez.com/audio/pitbull.mp3" type="audio/mpeg">
        <source src="http://demo.codesamplez.com/audio/music.ogg" type="audio/ogg">
</audio>
<audio id="audio_test2">
    <source src="http://demo.codesamplez.com/audio/pitbull.mp3" type="audio/mpeg">
        <source src="http://demo.codesamplez.com/audio/music.ogg" type="audio/ogg">
</audio>
<div id="hoverme1">Hover me</div>
<div id="hoverme2">Hover me</div>

Open in new window

Duplicate your code for each DIV changing the target audio tag
$("#hoverme1").hover(function () {
    $("#audio_test1").trigger('play');
}, function () {
    $("#audio_test1").trigger('pause');
})
$("#hoverme2").hover(function () {
    $("#audio_test2").trigger('play');
}, function () {
    $("#audio_test2").trigger('pause');
})

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GaryCommented:
And secondly, how do I apply a sound to a like a regular "close button"?
Just apply the same methodology
<div id="close">Close</div>
<audio id="close_sound">
    <source src="http://demo.codesamplez.com/audio/pitbull.mp3" type="audio/mpeg">
        <source src="http://demo.codesamplez.com/audio/music.ogg" type="audio/ogg">
</audio>
...
$("#close").click(function () {
    $("#close_sound").trigger('play');
})

Open in new window

0
colonelblueAuthor Commented:
I think I love you Gary!

Thank you!!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GaryCommented:
*blushing*
0
colonelblueAuthor Commented:
Experts like Gary is why I have stayed subscribed. A credit to your site and service.
Thank you!
0
GaryCommented:
I'm like a beetroot!
0
colonelblueAuthor Commented:
LMAO!!! :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.