如何在使用jQuery加载页面之前隐藏HTML元素 [英] How do I hide an HTML element before the page loads using jQuery

查看:166
本文介绍了如何在使用jQuery加载页面之前隐藏HTML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些显示或隐藏div的JQuery代码.

I have some JQuery code that shows or hides a div.

$("div#extraControls").show();   // OR .hide()

我最初希望div不可见,所以我使用了:

I initially want the div to be not visible so I used:

$(document).ready(function() {
    $("div#extraControls").hide();
});

但是,在浏览器上,内容加载一秒钟可见,然后消失,这不是我想要的.

However, on the browser, the content loads visible for a second before disappearing, which is not what I want.

如何设置页面加载前的hide元素,同时保持使用脚本动态显示hide的能力?

How do I set the hide the element before the page loads whilst keeping the ability to show hide it dynamically with a script?

推荐答案

div.hidden
{
   display: none
}

<div id="extraControls" class="hidden">
</div>

$(document).ready(function() {
    $("div#extraControls").removeClass("hidden");
});

这篇关于如何在使用jQuery加载页面之前隐藏HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆