Is the event target in Vue.js showing as null?

In my component, there are two buttons styled differently but with the same "mouseEnter" event.

<template>
  <div>
      <a 
          class="button red" 
          href="/about" 
          @mouseover="mouseEnter">  
          <svg viewBox="0    0 180 60">
              <path d="..."/>
          </svg>
          <span class="buttonSpan">About</span> 
      </a>
      <a 
          class="button green" 
          href="/contact" 
          @mouseover="mouseEnter">  
          <svg viewBox="0 0 180 60">
              <path d="..."/>
          </svg>
          <span class="buttonSpan">Contact</span>   
      </a>
  </div
</template>

When the "mouseEnter" event is triggered, I need to manipulate the path and span elements of the hovered button.

I'm trying to access them using event.target, but I am unable to select the span element as it returns null. However, everything works fine for the path element.

methods: {
  buttonEnter(event) {
    const buttonPath = event.target.querySelector('path')
    const buttonSpan = event.target.querySelector('span')
    
    ...
}

Is there a better way to reference the span element? Any alternative approaches would be appreciated.

Answer №1

when an event occurs, it will bubble up starting from the children of the original node where your listener is attached. Remember to utilize event.currentTarget

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to deleting a user from a list in AngularJS

I created a confirm button to delete a user from the list, but for some reason it's not working. Could someone please review my JavaScript code to see if there are any mistakes? Here is the JavaScript code: $scope.doDelete = function(user) { ...

What is the best way to streamline the code by mounting a Vue component using typescript in the beforeEach hook?

My code needs to be refactored to remove redundancy. describe("Stored id", () => { it("ID empty", () => { // Performing actions const wrapper = mount(SigninPage, options); const vm = wrapper.vm; }); it(" ...

Issue with Vue.js components where refs and transitions do not work in unison

Snippet: <transition name="slide-fade" mode="out-in"> <router-view ref="route" @resetSteps="handleResetSteps" @nextStep="handleNextStep"></router-view> </transition> Script comp ...

The issue arises when the jQuery $.get() method fails to deliver the expected response to the client, despite returning a status code of

I am having trouble with sending a REQUEST to a server in order to retrieve a message. I have tried using the jQuery method $.get(), and it seems to have successfully reached the server. However, I am facing an issue where I am unable to send a RESPONSE b ...

Update the text and background colors of all Vuetify components

Hey everyone, I'm trying to figure out how to change the text and background colors of all Vuetify components. I've tried using a custom theme but it's not working as expected. Any suggestions? :) const myCustomLightTheme = { dark: fals ...

Is there a way to open Internet Explorer using a specific URL from a different browser?

Imagine a scenario where a visitor lands on www.mysite.com using MS Edge. Instead of staying in Edge, I would like the page to recognize that Edge is being used and automatically launch Internet Explorer with the same URL. Is there a way to achieve this? ...

javascript dynamic content remains unaffected by ajax call

I'm a beginner with javascript and I am using a PHP variable to create links dynamically. Here is an example of how the variable is set: $addlink = '<button class="blueBtn btnSmall" id="current'.$product_id.'" onClick=addcart(' ...

Create an ASP button with drag and drop functionality

Is there a way to enable drag and drop functionality for an asp:Button element? Also, how can I retrieve the coordinates of the button after implementing jquery drag and drop? My goal is to store these coordinates in a database so that when I revisit the ...

Can encryption be implemented with a salt for added security instead of hashing?

I have been utilizing Node.js native crypto methods such as createCipherIv to encrypt objects. const algorithm = "aes256"; const inputEncoding = "utf8"; const outputEncoding = "hex"; const iv = randomBytes(16); export async f ...

Any ideas on how to extract binary data from PHP passthru using a JavaScript ajax request?

I am facing an issue with retrieving and playing an audio file from a server using JavaScript. The ajax call in my code doesn't seem to callback, and I'm not certain if I'm handling the audio correctly in JavaScript. Below is the PHP file t ...

Steps to make the placeholder in an MUI TextField component move to the top of the box instead of staying within the border:

I'm working on styling a text field in MUI to achieve the look shown in the image below: https://i.sstatic.net/JHhpf.png However, my current implementation looks like this: https://i.sstatic.net/5N7hH.png Currently, when I click inside the text fi ...

ngResource transformResponse guide on dealing with both successful and erroneous responses

When my API, built using expressJS, returns JSON data as a regular response, everything functions smoothly. However, when an error occurs, it returns an error code along with plain text by simply invoking res.sendStatus(401). This poses a challenge on my ...

Incorporating a Script into Your NextJS Project using Typescript

I've been trying to insert a script from GameChanger () and they provided me with this code: <!-- Place this div wherever you want the widget to be displayed --> <div id="gc-scoreboard-widget-umpl"></div> <!-- Insert th ...

Enforcement of AJAX Header Modification

I am currently in the process of developing an Apache Cordova application for Android. My goal is to have the ability to customize the headers for the AJAX requests that are being sent out, which includes fields such as Host, Origin, and Referer. Due to ...

The database threw an error: "Duplicate key found in collection causing MongoError: E11000"

I'm currently in the process of updating an object within an array found in a document "state": [], "users": [{ "ready": false, "_id": { "$oid": "5fb810c63af8b3 ...

Is there a way to get an iframe to mimic the behavior of other media elements within a horizontal scrolling container?

Take a look at this code snippet: $(document).ready(function() { $('.scrollable-area').on('wheel', function(e) { var scrollLeft = $(this).scrollLeft(); var width = $(this).get(0).scrollWidth - $(this).width(); var delta ...

What is the best way to find the maximum and minimum values within a JSON object that is populated from user inputs using only JavaScript?

Here is a simple form that stores data at the following link: https://jsfiddle.net/andresmcio/vLp84acv/ var _newStudent = { "code": code, "names": names, "grade": grades, }; I'm struggling to retrieve the highest and lowe ...

Develop and arrange badge components using Material UI

I'm new to material ui and I want to design colored rounded squares with a letter inside placed on a card component, similar to the image below. https://i.stack.imgur.com/fmdi4.png As shown in the example, the colored square with "A" acts as a badge ...

Implementing a div element within an autosuggest feature

i am currently integrating the bsn autosuggest into my project could someone please guide me on how to insert a div in the result so that it appears like this <div style="left: 347px; top: 1024px; width: 400px;" class="autosuggest" id="as_testinput_x ...

Issue with Masonry layout not adjusting to change in window size

Something seems to be fixed on displaying four rows, no matter the size of the window. Previously, it would adjust to three rows or fewer as the browser was resized. I recently played around with columnWidth, but reverting it back to 250 doesn't seem ...