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

107
Views
Event listener not firing in Vue

I want to toggle an element's visibility on keypress in Vue. The problem is I see the event is attached to the element but is not firing. the template is :

    <h1 v-show="typeWriterEffectVisible">
    <div id="game-board" data-v-d95dafd8="">
     <div class="letter-row">
      <div class="letter-box"></div>
      <div class="letter-box"></div>
      // etc

Vue:

<script setup>

let typeWriterEffectVisible = ref(true);

onMounted(() => {
   const el = document.querySelector(
    "#game-board > .letter-row:first-child > .letter-box:first-child"
  );

  // add eventlistener to toggle off typewriter effect on page
  el.addEventListener("keyup", () => {
    console.log("Im in toggle");
    typeWriterEffectVisible.value = false;
  }); 

From the DOM inspector I see the event is attached to the element but eventlistener callback is never invoked. If I change el.addEventListener to document.addEventListener it works. But then event fires on any keystroke on page which is not efficient or necessary. Any insights welcome...

about 4 years ago · Juan Pablo Isaza
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!