Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

91
Views
get audio file from DOM and play it -- vuejs

Hi i am trying to get the audio element from the dom and play it The audio file will have the same "id" as the button.

So far i was able to get the button id but when i try to select the element by id i get an error.

Code:

<script>
export default {
  data() {
    return {};
  },
  methods: {
    play_audio(e) {
      //get button clicked
      const button = event.target.id;
      console.log(button);

      document.getElementById(button).play();
    },
  },
  mounted() {},
};
</script>

<template>
  <main>
    <div class="results">
      <div class="result" v-for="(item, index) in cover_xl">
        <div class="result_img">
          <img :src="cover_xl[index]" :alt="title[index]" />
          <button @click="play_audio" :id="preview[index]">Play</button>
        </div>
        <h2>{{ title[index] }}</h2>
        <audio :id="preview[index]">
          <source :src="preview[index]" />
        </audio>
      </div>
    </div>
  </main>
</template>

Thanks in advance

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!