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

136
Vistas
How to set listener for elements that has same style value?

I want to set a listener for all elements that have same style value, that it can be setted any where in their style attribte, .css file or <header> style tag. After a lot of search I reach this code:

    $("body").on("click", '[style*="cursor:pointer"]', function (e) {
        const ripple = new Ripple();
        ripple.create(e, this.tagName.toLowerCase() == "a" ? 'dark' : 'light');
    });

But it's not working. I tried style~="pointer" and this did not work either. Both JS and JQuery are great for me.

Note: I found other related questions like using filter, so don't tell me it's duplicated and in my case, if I want to use filter to find elements with .css(), my listener has to be set for all elements in a page, that is not logical and optimized.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Unfortunately you cannot use CSS selector to get easily all elements by their style values. This works only for those which have the value set directly in their style html attribute.

The only way how to solve it by JS you already mentioned. That is the filter function, but you are right that it would not be efficient at all.

But maybe there are other ways how to fix this issue? Because it is actually quite rare to set some element behavior based on their css value. More common way would be to set it by class-name or tag-name.

So I do not know the context, but I would try one of these ways:

  1. If you are able to adjust HTML, set specific class to all the elements you want to target.
  2. If you cannot change HTML, you can try to create an array with several common attributes (tag-name, class-name) targeting your elements and based on it add the listener.
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