Forum:Javascript loading too early

Hi everybody, I'm trying to create a template, in which every user can choose what to see by adding a simple variable declaration in his/her own monobook.js

You can see the javascript code here (between comments), and the template is here (you can't see anything because every tag div has display:none until javascript decides which div to show)

I tried this script locally on my computer, on a simple html page, and if the script were loaded after the page, there was no problem, and this append only if the tag was added at the bottom of. Here instead the script is loaded before the rest of the page, and obviously can't substitute "display:none" with something else, if it doesn't still exist.

What can I do to make this template work automatically, ie without using any input from the user?

Thanks in advance, and I hope my translation is clear. --MFH(talk) 01:19, 24 January 2009 (UTC)


 * Using just CSS isn't an option? since they would need to have an entry in their monobook.js anyway (= user input) -- Sixorish 05:37, 24 January 2009 (UTC)


 * What do you mean? CSS are used to make the template invisible, but, as far as I konw, to make it dynamically visible javascript is needed. Or is there a trick I didn't consider? --MFH(talk) 10:56, 24 January 2009 (UTC)


 * Put the if inside a function, and call that function when the page has finished loading. I changed the code, so it should work now: --Ciencia Al Poder (talk) -WikiDex 10:58, 24 January 2009 (UTC)


 * Now it works greatly! Many thanks for the help. --MFH(talk) 11:27, 24 January 2009 (UTC)


 * this makes it visible for me:
 * #editintroCancellazione,
 * #editintro,
 * #editintroCancellazione,
 * #editintroAccusa,
 * #editintroRestauro,
 * #editintroScadenza,
 * #editintroFormattazione {display:block !important}


 * afaik there's no difference between using JS and CSS for this? -- Sixorish 12:00, 24 January 2009 (UTC)