markyeoj
markyeoj

Reputation: 369

Hide div with specific class while page is loading then show again after load

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.

Upvotes: 2

Views: 18586

Answers (4)

Harvinder Kheng
Harvinder Kheng

Reputation: 44

CSS:

.hidden { display: none; }

HTML:

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

JQUERY:

$(function () {
     $('#blah').removeClass('hidden');
 });

Upvotes: 0

Nuwan Dammika
Nuwan Dammika

Reputation: 587

<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")});

Upvotes: 0

user2415992
user2415992

Reputation: 521

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

Upvotes: 10

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?

Upvotes: 2

Related Questions