create if conditional based on css properties

This question already has an answer here:

  • Check if element is visible in DOM 17 answers

  • This is a way to determine it for all css properties including visibility: this works for properties set in a external css file, internal embedded styles, or inline styles! Note: the document MUST be loaded before executing the script!

    I have tested this out and it works with css rules set in inline, embedded, and external.

    html:

            <div id="element" onload="test();">div content</div>
    

    css:

            #element
            {
            visibility:hidden;
            }
    

    javascript:

            function test()
            {
                var element = document.getElementById('element');
                 if(element.style.visibility == 'hidden'){
                alert('hidden');
                }
               if(element.style.visibility == 'visible')
    
    
        {
        alert('visible');
             {
        if(element.style.visibility == 'collapse')
        {
        alert('collapsed');
        }
        if(element.style.visibility == 'initial')
        {
        alert('initial');
        }
        if(element.style.visibility == 'inherit')
        {
        alert('inherit');
        }
            }
    

    I have used this before.

    链接地址: http://www.djcxy.com/p/83570.html

    上一篇: angular2:有没有办法知道组件何时被隐藏?

    下一篇: 根据CSS属性创建条件