What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

Triggering a link if wrapped in an <em> tag

r43gf34gsf

New member
I am having an issue where a modal isn't triggering if it is wrapped in an <em> 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
JavaScript:
$(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
 
by changing `e.target` to `e.currentTarget` , it worked.

JavaScript:
  $('.modal-button').click(e => {
    e.preventDefault();
    $(e.currentTarget).closest('.modal').add('body').addClass('open');
    openModals.push($($(e.currentTarget).attr('href')).show());
  });
 
Back
Top