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

133
Views
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 answers
Answer question

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 Report
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!