0

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');
        });
2
  • The whole concept (hardcode list of elements excluded from behaviour) isn’t exactly clean, though. What does deleting this cookie mean? Commented Mar 21, 2022 at 19:30
  • Yea that is true! A strange request from a client and how a page is built I have to set cookies but delete them conditionally. thanks for advice! Commented Mar 21, 2022 at 19:37

1 Answer 1

4

.not():

$("a[href]").not(excludes.join())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.