Note that there are some explanatory texts on larger screens.

plurals
  1. POonMouseOver/onMouseOut fires on Child elements
    primarykey
    data
    text
    <p>This is my basic code:</p> <pre><code>&lt;script type="text/javascript"&gt; 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)"); } &lt;/script&gt; &lt;div class="jp-audio" onMouseOver="play(\''.$id.'\');" onMouseOut="end(\''.$id.'\');"&gt; //child elements, id from PHP &lt;/div&gt; </code></pre> <p>This plays audio when the div is hovered over. There are several divs (that each play different audio).</p> <p>But hovering over child elements in each div (like text) will stop the audio.</p> <p>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.</p> <p>Other solutions require using .hover() etc. But then how would I get the id of which file to play?</p> <p>I hope that makes sense. I'm finding it hard to explain what I mean.</p> <p>Any help would be appreciated.</p> <p>Now my working code is:</p> <pre><code>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); }); &lt;div class="jp-audio" file-id="'.$id.'"&gt;stuff&lt;/div&gt; </code></pre> <p>It's important to have the variables before the .hover, especially when the content is dynamically loaded based on user input.<br /> I had it around the other way and when using innerHTML it would not work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload