Forum Moderators: open
<h5>COLLAPSIBLE TITLE</h5>
<div class="body">
<ul>
<li><a href="...">MENU ITEM 1</a></li>
<li><a href="...">MENU ITEM 2</a></li>
<li><a href="...">MENU ITEM 3</a></li>
</ul>
</div>
<body>
<div id="foo">...</div>
<script type="text/javascript">
// DOM now contains a foo element
var foo = document.getElementById('foo');
foo.style.display = 'none';
</script>
... More content ...
</body>
YAHOO.util.Event.onContentReady("basicmenu", function () {
var oMenu = new YAHOO.widget.Menu("basicmenu");
oMenu.render();
oMenu.show();
});
<script type='text/javascript'>
document.write("<style type='text/css'>"+
".collapsible {height:0;}"+
"</style>");
</script>
let's say you place a script in the head section after a link to an external stylesheet, set to run immediatly. Will that script be executed before the body loads?
<style type='text/css'>
.collapsible {height:0;}
</style>
.collapsible { height: 0; }
.no-js .collapsible { height: auto; }
if (document.styleSheets[0]) {
// IE only - this is downside two
if (document.styleSheets[0].addRule()) {
document.styleSheets[0].addRule("#some-block", "display:none");
}
// Everyone else, as usual
else {
document.styleSheets[0].insertRule("#some-block{display:none;}", 0);
}
}
<div id="slideMenu">
<ul>
<li>Menu item #1</li>
<li>Menu item #2</li>
<li>Menu item #3
<ul>
<li>Submenu item #1</li>
</ul>
</li>
</ul>
</div>
// Locate the UL menu on my page by passing the ID, and also locate the child UL item
var slidemenu = {
animateduration: {over: 200, out: 200}, //duration of slide in/ out animation, in milliseconds
buildmenu: function(menuid) {
$(document).ready(function() {
var $mainmenu = $("#" + menuid + " > ul");
var $headers = $mainmenu.find("ul").parent();
$headers.each(function(i) {
var $curobj = $(this);
this._dimensions = {
w: $(this).outerWidth(),
h: $(this).outerHeight()
};
$curobj.hover(function(e){
var $targetul = $(this).children("ul:eq(0)");
this._offsets = {
left: $(this).position().left,
top: $(this).position().top
};
var x = this._offsets.left + this._dimensions.w;
var y = this._offsets.top;
if(1 > $targetul.queue().length) //if 1 or less queued animations
$targetul.css({
top: y,
left: ($(this).parent().position().left+$(this).parent().outerWidth()) + "px",
width: this._dimensions.w + "px"
}).show("fast");
},
function(e){
var $targetul = $(this).children("ul:eq(0)");
$targetul.hide("fast");
}
);
//end hover
$curobj.click(function(){
$(this).children("ul:eq(0)").hide()
})
});
$mainmenu.find("ul").css({display:'none', visibility:'visible'});
});
}
}
slidemenu.buildmenu('slideMenu');
As for removing the class, that would mean the script has to be somewhere in the body tag and before the menu, which would mean it still delays loading slightly.