简体   繁体   中英

How to store null values in var in javascript

 var img2 = document.getElementById('ImgCorrectConditon2');//img2 = null
 img2.style.visibility = 'hidden';

If its a null. exception / error occurs and next line of codes not executing. How to stop executing line of code if any, control is null

try this code by checking img2 is not null

 var img2 = document.getElementById('ImgCorrectConditon2');//img2 = null
 if(img2 != null )
 {  
      img2.style.visibility = 'hidden';
 }

Simply check for null ?

if(img2 != null) {
   img2.style.visibility = 'hidden';
}

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