Hacking in a related issue is, in my opinion, very bad advice. In this case, it is better to include some script immediately after your accordion elements.
<div id="accordion">...</div> <script type="text/javascript">...</script>
However, the inline script mixed with your HTML markup is a bad idea and should be avoided as much as possible. For this reason, it’s ideal to include a built-in function call only function declared in your external script file. (When you link to an external script ( <script src="..."> ), the rendering of your page will pause until it loads.)
<html> <head> <script type="text/javascript" src="script.js"></script> </head> <body> ... <div id="accordion">...</div> <script type="text/javascript">renderAccordion();</script> ... </body> </html>
Of course, the right way to do this is to simply connect to the DOM ready event from script.js and not use the inline script at all. However, this opens up the possibility of creating Flash content on extremely slow connections and / or very large documents, where loading all of the HTML itself takes several seconds. This, however, is a much cleaner approach - your script is guaranteed to be loaded before anything is displayed; the only question is how long does it take to get the DOM ready. Using jQuery in script.js :
$(document).ready(function() {
The clever use of <style> and <noscript> does a good job of ensuring that your accordion does not have a flash of all content; however, this method will have the opposite effect. there will be a flash without content.
When the page loads, your accordion will be completely hidden ( display:none; ), and then when your script finally executes and returns the display to block , the accordion unexpectedly materializes and presses everything below it. This may or may not be acceptable - not there will be so much movement, but still have to jump after they were originally made.
In any case, do not wait until onload makes your accordion. onload does not work until everything is turned on, including all images - fully loaded. There is no reason to wait for image downloads; you want to make your accordion as soon as possible.