Javascript 在javascript中隐藏div onload

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39307329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 22:26:41  来源:igfitidea点击:

Hide div onload in javascript

javascripthtmlblogsblogger

提问by Mandeep Singh

HTML

HTML

<div id="b-navbar-fg">
</div> 

JavaScript

JavaScript

<script>
   $(function(){
      $("#b-navbar-fg").hide() // try to hide google navigation bar
   });
</script>

This Function is executing in my google blogger page. But I am not able to hide this id on loading page.

此功能正在我的 google 博客页面中执行。但我无法在加载页面上隐藏此 ID。

EXAMPLE PAGE

示例页面

回答by Mandeep Singh

You can use as in following :

您可以使用如下:

JS

JS

window.onload = function() {
  document.getElementById('b-navbar-fg').style.display = 'none';
};

Jquery

查询

$(document).ready(function() {
    $("#b-navbar-fg").hide();
});

回答by Abhijeet

Try this code :

试试这个代码:

window.onload = function() {
  $("#b-navbar-fg").hide();
};

If above code does not work, try this one :

如果上述代码不起作用,请尝试以下代码:

$(document).ready(function() {
    $("#b-navbar-fg").hide();
});

回答by Nikit Barochiya

$(document).ready(function() {
    $('#div1').hide();
    $('#preview').on('click', function() {
            $('#div1').toggle(300);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div1">
First Div Hide
</div>

<div id="div2">
Second Div
</div>

<div id="preview" style="color:#999999; font-size:14px">
<button>Click</button
</div>