简体   繁体   English

无法通过Javascript查看DOM节点的样式可见性

[英]Can't see a DOM node's style visibility through Javascript

I need some logic in my Javascript to make a parentnode of a node in which an event was caught, disappear. 我需要在Javascript中添加一些逻辑,以使捕获事件的节点的父节点消失。 To be specific, the parent node is a PDF link, and both it and its child node (bmp image) both need to be invisible if the child fails to load. 具体来说,父节点是PDF链接,如果子节点无法加载,则其及其子节点(bmp图像)都必须不可见。 Here is what I have outlined as my event listener function: 这是我概述为事件侦听器功能的内容:

window.addEventListener('error', function(event) {
    console.log(event);
    if (event.target.id == "sheetBmp"){
        console.log("sheet bmp failed to load");
        //make the pdf disappear also
        e.target.parentNode.style.visibility=false;
        console.log("pdf nodeshould disappear");
    }
}, true);

and here is the styling: 这是样式:

    <a id=sheetPdf target='_blank'>
        <img id="sheetBmp" onLoad="this.style.visibility='visible'" onError="this.style.visibility='hidden'">
        </img>
    </a>

Note that I ran it through a debugger, and after the e.target.parentNode.style.visibility=false; 请注意,我是通过调试器在e.target.parentNode.style.visibility=false;之后运行的e.target.parentNode.style.visibility=false; line runs the property remains the same (blank quotes) and the visibility of the node remains visible on the webpage. 行运行时,属性保持不变(双引号),并且节点的可见性在网页上仍然可见。 Any assistance is greatly appreciated 非常感谢任何帮助

You are setting an invalid value ( false ) to the property, so the browser is discarding it. 您正在为属性设置一个无效值( false ),因此浏览器将其丢弃。

Acceptable values for the visibility property include "visible" and "hidden" . 可见性属性的可接受值包括"visible""hidden"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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