最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hide div with specific class while page is loading then show again after load - Stack Overflow

programmeradmin3浏览0评论

I want to hide an specific div class while page is loading. The structure is..

<div id ="container">
<div class="project-item tv"></div>
<div class="project-item radio"></div>
<div class="project-item radio"></div>
<div class="project-item tv"></div>
</div>

For example, I want to hide DIV with class radio while page is loading, then show them again after load. Thanks.

I want to hide an specific div class while page is loading. The structure is..

<div id ="container">
<div class="project-item tv"></div>
<div class="project-item radio"></div>
<div class="project-item radio"></div>
<div class="project-item tv"></div>
</div>

For example, I want to hide DIV with class radio while page is loading, then show them again after load. Thanks.

Share Improve this question asked Nov 13, 2013 at 3:59 markyeojmarkyeoj 3692 gold badges6 silver badges17 bronze badges 1
  • What I would try to do is make it so the div has the class "hidden" (which you can css to be display: none;) and then have some kind of function in the js remove the class after page load. – QuestionMarcs Commented Nov 13, 2013 at 4:02
Add a ment  | 

4 Answers 4

Reset to default 10

First, set it's CSS value to display:none

Then, in a Javascript file, the jQuery solution would be to use:

$(document).ready(function() {
     $("#yourdivid").show();
});

$(document).ready() makes sure that the entire DOM is loaded before the code inside the function is executed

Use CSS

hide div using css

div.radio {
    display:none;
}

js

Show div with class radio on DOM ready

$(document).ready(function () {
    $('div.radio').show();
});


Show div with class radio on load

$(window).load(function () {
    $('div.radio').show();
});

Read What is the difference between $(window).load and $(document).ready?

<style>
 div .radio  {display:none;}
</style>

<div id ="container">
<div class="project-item tv"></div>
<div class="project-item radio"></div>
<div class="project-item radio"></div>
<div class="project-item tv"></div>
</div>

in JS

$().ready(function() {$("div .radio").css("display":"block")});

CSS:

.hidden { display: none; }

HTML:

<div id="blah" class="hidden"><!-- content --></div>

JQUERY:

$(function () {
     $('#blah').removeClass('hidden');
 });
发布评论

评论列表(0)

  1. 暂无评论