Title: Problem with javascript
Last modified: May 29, 2025

---

# Problem with javascript

 *  Resolved [rebeccamantel](https://wordpress.org/support/users/rebeccamantel/)
 * (@rebeccamantel)
 * [1 year ago](https://wordpress.org/support/topic/problem-with-javascript-5/)
 * Hello
 * I have a problem that I added some javascript to make the audios play one after
   the other as soon as we play one but it doesn’t work for the audios in the filter(
   even though they have the same html structure than in the audios above which 
   work one after the other) This is my javascript code :
 * Do you know what could be interfering? Thank you so much for this amazing plugin!!!
 *     ```wp-block-code
       <script>document.addEventListener('DOMContentLoaded', () => {  const audioPlayers = Array.from(document.querySelectorAll('.audio-player'));  // Handle custom play buttons  const toggleButtons = document.querySelectorAll('.audio-toggle-btn');  toggleButtons.forEach((btn, index) => {    btn.addEventListener('click', () => {      // Pause all other audio players      audioPlayers.forEach((a, i) => {        if (!a.paused && i !== index) {          a.pause();        }      });      const targetAudio = audioPlayers[index];      // Toggle play/pause      if (targetAudio.paused) {        targetAudio.play().catch(err => console.log('Play error:', err));      } else {        targetAudio.pause();      }    });  });  // Auto-play next audio on 'ended'  audioPlayers.forEach((audio, index) => {    audio.addEventListener('ended', () => {      const nextIndex = index + 1;      if (audioPlayers[nextIndex]) {        // Pause all others before playing next        audioPlayers.forEach(a => a.pause());        // Delay slightly to prevent AbortError        setTimeout(() => {          audioPlayers[nextIndex].play().catch(e => {            console.log('Play prevented (likely due to browser policy):', e);          });        }, 100);      }    });  });});</script>
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fproblem-with-javascript-5%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [YMC](https://wordpress.org/support/users/wssoffice21/)
 * (@wssoffice21)
 * [1 year ago](https://wordpress.org/support/topic/problem-with-javascript-5/#post-18490248)
 * Hi!
 * Inside the post grid, audio files are launched and played. You need to take into
   account that the requests in the filter are asynchronous and this requires logic
   algorithms for working with JavaScript. Use plugin hooks (see docs) to manage
   the entire loading process.
   [https://github.com/YMC-22/smart-filter#js-api-filter–grids](https://github.com/YMC-22/smart-filter#js-api-filter--grids)

Viewing 1 replies (of 1 total)

The topic ‘Problem with javascript’ is closed to new replies.

 * ![](https://ps.w.org/ymc-smart-filter/assets/icon-128x128.png?rev=3354891)
 * [YMC Filter](https://wordpress.org/plugins/ymc-smart-filter/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ymc-smart-filter/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ymc-smart-filter/)
 * [Active Topics](https://wordpress.org/support/plugin/ymc-smart-filter/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ymc-smart-filter/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ymc-smart-filter/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [YMC](https://wordpress.org/support/users/wssoffice21/)
 * Last activity: [1 year ago](https://wordpress.org/support/topic/problem-with-javascript-5/#post-18490248)
 * Status: resolved