简体   繁体   中英

parentNode.remove() not working in IE

First of all, I'm very new with all that JavaScript stuff. I'm using parentNode.remove() to close a modal box on my site. Works perfectly in Firefox and Chrome, but nothing in IE (8-9-10-11...).

The link that I use to close the box looks like this:

<a onClick="parentNode.remove()" class="close">X</a>

Is there a way that I can tweak my onclick to work in Internet Explorer?

Thanks a lot!

remove(); is a jQuery method. Are you using jQuery? If so, you could do: $(this).parent().remove(); .

I don't know if this is just an example, but I would recommend creating a single function instead of adding individually.

$('a').on('click', function (e) {
  e.preventDefault();
  $(this).parent.remove();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM