Home > Software engineering >  How can I use an array of values as a jQuery selector argument?
How can I use an array of values as a jQuery selector argument?

Time:03-22

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');
        });

CodePudding user response:

.not():

$("a[href]").not(excludes.join())
  • Related