元素隐藏但 parent() 不

Element hides but parent() not

我试图在无法找到图像时隐藏图像的容器。到目前为止,这个隐藏了 "image not found" 图标的作品:

document.addEventListener("DOMContentLoaded", function(event) {
   document.querySelectorAll('img').forEach(function(img){
    img.onerror = function(){
        this.style.display='none';
    };
   })
});

但是当我改变这一行时:

this.display='none';

this.parent().display='none';

它不工作。 如何隐藏容器镜像?

这不是 jQuery,只是很好 DOM。

this.parentElement.style.display = 'none';