Skip to main content

Forums

This topic contains 1 reply, has 1 voice, and was last updated by  j7f4f2a4fds2 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #296998

    j7f4f2a4fds2
    Participant

    I am having an issue where a modal isn’t triggering if it is wrapped in an tag.
    In my example, if you click in the “normal” font-style part of the link, it fires properly, if you click where the italics are, it won’t.

    Any ideas?

    JS

    $(function () {
      const openModals = [];
      $('.modal-button').click(e => {
        e.preventDefault();
        $(e.target).closest('.modal').add('body').addClass('open');
        openModals.push($($(e.target).attr('href')).show());
      });
      $(window).add('.close').click(e => {
        e.stopPropagation();
        if ($(e.target).is('.modal, .close')) {
          const closing = openModals.pop().addClass('modal-content-active');
          setTimeout(() => {closing.hide().removeClass('modal-content-active')}, 0);
          if (openModals.length > 0) {
            openModals[openModals.length - 1].removeClass('open');
          } else $('body').removeClass('open');
        }
      });
    });
    

    FIDDLE
    https://jsfiddle.net/postcolonialboy/h70bkej9/30/

    #296999

    j7f4f2a4fds2
    Participant

    by changing e.target to e.currentTarget , it worked.

    $(‘.modal-button’).click(e => {
    e.preventDefault();
    $(e.currentTarget).closest(‘.modal’).add(‘body’).addClass(‘open’);
    openModals.push($($(e.currentTarget).attr(‘href’)).show());
    });

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star