Kam
Kam

Reputation: 6008

run jquery before document is ready

I have the following script:

$(document).ready(function() {

$('*:lang(English)').hide();
$('*:lang(French)').hide();
});

What I need is that every element with attribute lang="English" or lang="French" to be hidden initially.

but now when I load my website it glitches. since html starts being rendered before $(document).ready becomes well "ready". So as a consequence all elements with the above specified attribute will be shown for a split second.

Is there a way to put a handler on every *:lang(English) before document is ready so I don't see anymore glitches?

Upvotes: 0

Views: 201

Answers (1)

Evan Hahn
Evan Hahn

Reputation: 12712

You should probably remove the jQuery and do this with CSS:

*:lang(en), *:lang(fr) {
    display: none;
}

Then, if you want to show only one language, for example, do that with jQuery.

$(document).ready(function() {
    $('*:lang(fr)').show();
});

Upvotes: 2

Related Questions