Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
I target all links using a.forEach((item) ...is it possible to include 'or class x' when needing to target non-anchors?

This script is on a custom Javascript cursor. It works as intended, however I want the mouse to react the same way when it hovers over an single element (img) that is not an a - which is what the script currently targets.

Is there a way I can adapt the script to essentially look for 'target anchors or an element with a class of .link' (for example). Or would I need to duplicate the block of code and use getElementsByClassName? Maybe I'd be better off using something like my data- to target elements rather than all a elements?

document.addEventListener("mousedown", function () {
  cursor.classList.add("cursor--click");
});

document.addEventListener("mouseup", function () {
  cursor.classList.remove("cursor--click");
});

a.forEach((item) => {
 item.addEventListener("mouseover", () => {
    cursorTrail.classList.add("cursor-trail--hover");
 });
 item.addEventListener("mouseleave", () => {
   cursorTrail.classList.remove("cursor-trail--hover");
 });
});

a.forEach((item) => {
 const interaction = item.dataset.interaction;

 item.addEventListener("mouseover", () => {
   cursor.classList.add(interaction);
 });
 item.addEventListener("mouseleave", () => {
   cursor.classList.remove(interaction);
 });
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can select elements using an arbitrary CSS-selector by using document.querySelectorAll

In your case, you would do something like this:

let links = document.querySelectorAll('a, .link');
links.forEach((item) => {
   ...
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda