I'm adding a style tag with text content from localStorage for an element which has inline style display:none;
. Afterwards I call a script file which makes that element visible. But at that time it seems that the browser hasn't parsed the styles yet. So for a short moment the element style is shred. I want to prevent that - so is there a way to check, if the styles has been parsed?
Here is the code:
HTML:
<div id="my_element" style="display:none;">
//...content of the element goes here
</div>
JS:
try{
if (typeof(Storage) !== "undefined" && typeof localStorage !== "undefined" && localStorage !== null && localStorage.getItem("stylesheet") !== null) {
var stylesheet = JSON.parse(localStorage.getItem('stylesheet'));
$('<style>').attr('id', 'my_stylesheet').text(stylesheet).prependTo('#my_element');
}else{
load_css_from_server();
}
}catch(e){
load_css_from_server();
}
load_my_external_javascript_and_append_to_head();
External Javascript File:
$(document).ready(function(){
//some code here
$('#my_element').slideDown('slow');
//some code there
});
I already tried to check if the Style Element with the ID my_stylesheet
exists but that doesn't mean that the browser interpreted and rendered the css. Is it possible to check that?