Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6356293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:56:07+00:00 2026-05-24T22:56:07+00:00

This is my basic code: <script type=text/javascript> function play(id){ $(#player+id).jPlayer(play, 0); $(#jp-play+id).css(background-color, #999999); $(#jp-pause+id).css(background-color,

  • 0

This is my basic code:

<script type="text/javascript">

function play(id){
    $("#player"+id).jPlayer("play", 0);
    $("#jp-play"+id).css("background-color", "#999999");
    $("#jp-pause"+id).css("background-color", "#999999");
    $("#jp-play"+id).css("background-image", "url(images/voice_over/hover.png)");
    $("#jp-pause"+id).css("background-image", "url(images/voice_over/hover.png)");
}

function end(id){
    $("#player"+id).jPlayer("stop");
    $("#jp-play"+id).css("background-color", "#656565");
    $("#jp-pause"+id).css("background-color", "#656565");
    $("#jp-play"+id).css("background-image", "url(images/voice_over/normal.png)");
    $("#jp-pause"+id).css("background-image", "url(images/voice_over/normal.png)");
}
</script>


<div class="jp-audio" onMouseOver="play(\''.$id.'\');" onMouseOut="end(\''.$id.'\');">
    //child elements, id from PHP
</div>

This plays audio when the div is hovered over.
There are several divs (that each play different audio).

But hovering over child elements in each div (like text) will stop the audio.

I understand that this is something to do with bubbling/propagation.
I am using jQuery and simply tried adding event.stopPropagtion(); to the functions but it didn’t work.

Other solutions require using .hover() etc.
But then how would I get the id of which file to play?

I hope that makes sense.
I’m finding it hard to explain what I mean.

Any help would be appreciated.

Now my working code is:

var play = function() {
    var id = $(this).attr('file-id');
    $("#player"+id).jPlayer("play", 0);
    $("#jp-play"+id).css("background-color", "#999999");
    $("#jp-pause"+id).css("background-color", "#999999");
    $("#jp-play"+id).css("background-image", "url(images/voice_over/hover.png)");
    $("#jp-pause"+id).css("background-image", "url(images/voice_over/hover.png)");
}

var end = function() {
    var id = $(this).attr('file-id');
    $("#player"+id).jPlayer("stop");
    $("#jp-play"+id).css("background-color", "#656565");
    $("#jp-pause"+id).css("background-color", "#656565");
    $("#jp-play"+id).css("background-image", "url(images/voice_over/normal.png)");
    $("#jp-pause"+id).css("background-image", "url(images/voice_over/normal.png)");
}

$(document).ready(function(){
   $('.jp-audio').hover(play, end);        
});

<div class="jp-audio" file-id="'.$id.'">stuff</div>

It’s important to have the variables before the .hover, especially when the content is dynamically loaded based on user input.
I had it around the other way and when using innerHTML it would not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:56:09+00:00Added an answer on May 24, 2026 at 10:56 pm

    A better way to do it is set $id to be a attr of the html element

    $(document).ready(function(){
       $('.js-audio').hover(play, end);        
    });
    
    var play = function() {
       var id = $(this).attr('file-id');
       ....
    }
    
    <div class="js-audio" file-id="$id"></div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code runs as follows, <script src=../../Content/js/jquery.simplemodal.js type=text/javascript> </script> <script src=../../Content/js/jquery.js type=text/javascript></script> <script src=../../Content/js/basic.js
The basic pseudo code looks like this: void myFunction() { int size = 10;
this code is the base of lexer , and it does the basic operation
This is a really basic question but... I have some code like this var
I got this doubt while writing some code. Is 'bool' a basic datatype defined
I am writing a fairly basic GreaseMonkey script that locates text in a specific
I'm learning javascript and jquery and have written a very basic script inside my
Unfortunately, this may not be a valid Code-Golf question as it is likely Javascript
I've created this basic 3D Demo using OpenGL/SDL. I handled the keyboard callback so
Forgive my ignorance in asking this basic question but I've become so used to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.