banu prakash banu prakash - 2 months ago 11
CSS Question

how to get audio on clickeing the image using javascript and pause when playing

<img class="cl"src="photo/198.jpg"/></br>
<audio class="cs" controls>
<source src="audio/198 banu nagamothu.mp3" type="audio/mpeg">

I dont want controls to audio first but when i clicked the image audio should played using javascript and html


Use AudioElement.paused property!

$('.cl').click(function() {
  var DOMElem = $('.cs').get(0);
  DOMElem.paused ? : DOMElem.pause();
<script src=""></script>
<img class="cl" src="photo/198.jpg" />
<audio class="cs">
  <source src="" type="audio/mpeg">