Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I use an array of values as a jQuery selector argument?

I would like to have an array of classes/IDs and then on a click function using jQuery pass each of those values to that function to exclude them from the event rather than have numerous :not calls as I currently have which works but is a bit ugly to me.

 var excludes = [
          '#seeMore',
          '#readMore',
          '#isiToTop',
          '.btn-cta--download',
          '.videoModalTrigger',
        ];

        $(
          "a[href]:not('#seeMore'):not('#readMore'):not('#isiToTop'):not('.btn-cta--download'):not('.videoModalTrigger')"
        ).click(function () {
          _siteNs.Utils.deleteCookie('5_Signs');
        });

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.not():

$("a[href]").not(excludes.join())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading