Change element display none back to default style value JS

前端 未结 6 994
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 11:22

I have a function in JS that hides the element parsed:

function hide(id){
  document.getElementById(id).style.display = \"none\";
}

How can

6条回答
  •  离开以前
    2020-12-20 11:59

    You need just assign it to empty value:

    document.getElementById(id).style.display = "";
    

    Or using removeProperty method:

    document.getElementById(id).style.removeProperty( 'display' );
    

    But note that removeProperty will not work on IE<9.

    If you want to get original CSS value you will need probably to get it from empty