Check if element is visible in DOM

后端 未结 18 2078

Is there any way that I can check if an element is visible in pure JS (no jQuery) ?

So, for example, in this page: Performance Bikes, if you hover over Deals (on the

18条回答
  •  半阙折子戏
    2020-11-22 08:07

    This is a way to determine it for all css properties including visibility:

    html:

    div content

    css:

    #element
    {
    visibility:hidden;
    }
    

    javascript:

    var element = document.getElementById('element');
     if(element.style.visibility == 'hidden'){
    alert('hidden');
    }
    else
    {
    alert('visible');
    }
    

    It works for any css property and is very versatile and reliable.

提交回复
热议问题