Dealing with mouseover and mouseout events for ul li elements in Angular 9: An easy guide

Having trouble showing and hiding the span tag using mouseover and mouseout events. The ul and li elements are generating dynamically, so I attempted to toggle the display between block and none but it is not working as expected. Does anyone have a solution for this issue? Any help would be greatly appreciated.

Here is the code in app.component.html:

<ul class="nav-tabs">

<li class="item"> 
  <a>Test1</a>
  <span> -On </span> 
</li>
<li class="item"> 
  <a>Test2</a>
  <span> -On </span> 
</li>
<li class="item"> 
  <a>Test3</a>
  <span> -On </span> 
</li>

</ul>

And here is how it's handled in app.component.ts:

ngOnInit() {
let m = this.elRef.nativeElement
  .querySelector('#list > ul')
  .querySelectorAll('li');

m.forEach(el => {
  el.addEventListener('mouseover', function(e) {
    console.log('Event triggered');
    el.nextElementSibling('span').style.display = 'block';
  });
  el.addEventListener('mouseout', function(e) {
    console.log('Event out');
    el.nextElementSibling('span').style.display = 'none';
  });
});

}

You can see a demo of the issue here: https://stackblitz.com/edit/angular-ivy-qw6hvg?file=src%2Fapp%2Fapp.component.ts

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

Is there a method to enhance the efficiency of generating the code coverage report in VSTS?

What are the possible reasons for the extended duration (>1 min) required to generate the code coverage report when running the associated command in VSTS? Are there any strategies that can be implemented to streamline this process? ...

Retrieving a global variable within a nested function

I am encountering a scope issue with my nested function while trying to pass two global variables. I need some help as I keep getting this error when running the code: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'use ...

Tips for changing a "raw" DOM Event into a React SyntheticEvent

Currently, I am working with two separate libraries. The first library emits "raw" DOM events (lib.dom.d.ts), while the other library consumes React.SyntheticEvents. I am seeking advice on the most efficient method to transform the raw event into a Synthe ...

Incorporating a <script> tag in Angular 8 to reference an external JavaScript file from a different website

I am currently using Angular 8 and its CLI to develop my website. Issue: I need to include an external JavaScript file from a different website by adding a <script> tag, for example: <script src="https://www.wiris.net/demo/plugins/app/WIRISplugin ...

Utilize the identical function within the reducer for numerous mat-slide-toggle and checkboxes in component.html

I'm currently diving into the world of Angular and ngrx while tackling a project focused on enabling users to create forms. In this project, users can add various form elements (such as labels, text fields, dropdown menus, checkboxes, etc.) from a sid ...

How to resolve the issue of any data type in Material UI's Textfield

I am seeking clarity on how to resolve the TypeScript error indicating that an element has an 'any' type, and how I can determine the appropriate type to address my issue. Below is a snippet of my code: import { MenuItem, TextField } from '@ ...

Ways to deduce or implement intellisense for parameter types in overloaded functions

Currently, I am developing an Electron application where numerous events are being passed around with specific listeners assigned to each event. One example is BrowserWindow.on: Electron.BrowserWindow.on(event, listener) The event can take on values such ...

What is the best way to extract data from Azure Data Lake and showcase it within an Angular-2 interface?

I am facing a challenge where I need to retrieve files with content from Azure Data Lake and display them in an Angular-2 Component. The issue is that when using the List File Status() method, I am only able to obtain file properties, not the actual conten ...

How can I modify the join() function of an Array<MyType> in Typescript to instead return MyType instead of a string?

I am working with a specialized string type called MyType = string & { __brand: 'mytype' }. Is there a way to define an override for the Array.join method specifically for arrays of type Array<MyType> so that it returns MyType instead of s ...

Modify information in formArray

Let's take a look at this setup I have: Model: export class MapDetailModel{ id: number; lat: number; lon: number; alt: number; long: number; angle: number; distance?: number; pendenza?: number; } Html: <div clas ...

Stop the ion-fab-list from automatically closing when an element is selected within it

I'm having trouble getting a form to stay visible when a fab is clicked in my Ionic 4 app. Every time I click on a fab or another component within the ion-fab-list, the ion-fab-list automatically closes. How can I prevent this from happening and keep ...

Bringing together the functionality of tap to dismiss keyboard, keyboard avoiding view, and a submit button

On my screen, there's a big image along with a text input and a button at the bottom. The screen has three main requirements: When the user taps on the input, both the input and button should be visible above the keyboard The user must be able to ta ...

Angular HTML fails to update correctly after changes in input data occur

Within my angular application, there is an asset creator component designed for creating, displaying, and editing THREE.js 3D models. The goal was to implement a tree-view list to showcase the nested groups of meshes that constitute the selected model, alo ...

Best Practices for Utilizing NPM Modules with TypeScript

I am interested in developing an npm module using TypeScript. Can anyone suggest a best practice guide on how to start? Here are my questions: Node.js does not natively support TypeScript, so what is the recommended way to publish an npm module? Shoul ...

Structuring an Angular 2 Project

Embarking on a new project in Angular2, I find myself pondering the optimal structure for an Angular2 application. Imagine I have various pages such as home, auto-galleries, nearest-galleries, brands, cars, and selected-car. The navigation sequence could b ...

What is the best way to elucidate this concept within the realm of TypeScript?

While diving into my ts learning journey, I came across this interesting code snippet: export const Field:<T> (x:T) => T; I'm having trouble wrapping my head around it. It resembles the function definition below: type myFunction<T> = ...

Merge MathJax into SystemJS compilation

I utilize SystemJS to construct an Angular 2 project and I am interested in incorporating MathJax into a component. To start using it, I executed the following commands: npm install --save-dev mathjax npm install --save @types/mathjax Now, I have success ...

Executing mocha using Typescript results in a TypeError [ERR_UNKNOWN_FILE_EXTENSION] because the file extension ".ts" is unrecognized

I've been experimenting with Typescript and Mocha to write some tests. After following the documentation, I've set up the following: package.json { //... "scripts": { "test": "mocha", }, //... } .mocharc.j ...

After implementing rewrites, my dynamic routes in Next.js are no longer functioning as expected

This is the current structure of my project and it was working fine before I added rewrites to my project. https://i.sstatic.net/X989W.png -dashboard --admin --page.tsx ---[adminId] ---page.tsx --cars --page.tsx ---[carId] ---page.tsx -lo ...

Conversations with Dialogflow and Express: Enhancing Fulfilment

I'm facing a challenge with receiving responses from dialogflow, even though other express calls are functioning properly. I believe the issue lies within the agents, but I am unsure of the specific problem or how to resolve it. That's why I hav ...