0

I have div which is communicate with data.txt by js

when data.txt has new rows it displaying on div in live action without refreshing my page

Example of div

Everything is working and what i can't figured out is how i can play sound when new rows added on my div in live?

Hope my question is clear

  • You asked a remarkably similar question earlier I believe?! You have not shared any code so a proper answer cannot be given – Professor Abronsius Jan 01 '22 at 15:42
  • Use a [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) – Spectric Jan 01 '22 at 15:44
  • @Professor Abronsius its simple question the div recieve data from an file txt which is called data.txt displayed on div just need some js code to add the sound when the new data is loaded in div i think its not big deal – anchor luxury Jan 01 '22 at 15:48
  • 1
    It probably is not a `"big deal"` but the fact remains that you have not shared any code. How is anyone supposed to know how/where to trigger the playing of sounds? StackOverflow is to help people that have problems with their code rather than to provide bespoke solutions to all and sundry who just happen to ask. – Professor Abronsius Jan 01 '22 at 15:54
  • @Professor Abronsius the data shown here
    data shown here
    so js should work with id= of the div to capture any new line and if new line added sound should play
    – anchor luxury Jan 01 '22 at 16:17
  • So - you wrote some code to query a csv file and update the HTML display but will not share what that is or how it works. The obvious way to play the sound would be within this function when it updates the displayed data. @Spectric mentioned a `MutationObserver` - that is another way you could do it. The essential part of [playing audio](https://stackoverflow.com/questions/9419263/how-to-play-audio) has been covered before and there are plenty of resources out there to help you with how to do it ~such as [MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) – Professor Abronsius Jan 01 '22 at 16:32

0 Answers0