What does style.display = '' actually do?

前端 未结 4 1422
太阳男子
太阳男子 2020-12-12 13:19

After researching this issue for a couple of hours, I found that one of the most efficient ways to toggle a page element\'s display (in HTML) is to do something like:

<
4条回答
  •  有刺的猬
    2020-12-12 14:01

    It removes the value for the display property so that the default value is used.

    It does not reset the original display property.

    If you for example have this:

    b
    

    And do this:

    document.getElementById('test').style.display = 'inline';
    document.getElementById('test').style.display = '';
    

    the display style used for the element ends up being inline because that's the default for the element, it is not reset back to the style specified in the HTML code.

提交回复
热议问题