by @codeexamples

How to check if a element is hidden in JavaScript

Home » javascript » How to check if a element is hidden in JavaScript

In the below example, we are checking if a h1 element is hidden by using display:none property.

const h1 = document.querySelector('.myHead');

if(h1.style.display === 'none'){
    console.log('im hidden');
}else{
    console.log('im visible');
}

Similarly, we can check if a element is hidden by using visibility:hidden property.

const h1 = document.querySelector('.myHead');

if(h1.style.visibility === 'hidden'){
    console.log('im hidden');
}else{
    console.log('im visible');
}