views:

150

answers:

2

On some of my pages I want Superfish (menu plugin) to unfold one of the first level options by default as soon as the page opens. I attributed this option ul an id="me", and trying to implement "onInit" function, but it does not work. Could someone please look? Thanks.

jQuery(function(){
jQuery('ul.sf-menu').superfish({
 onInit: function(){$('#me',this).show();},
 });
});
A: 

do you get any javascript errors?

possible problems with the snippet you posted:

  • onInit does not get called for whatever reason. check with alert or console.log
  • this in onInit is not a DOMElement. it might be a jquery object. check with console.log

plus, you have a syntax error in there: the last property in an object literal must not be followed by a comma.

just somebody
Thank you for your answer, I will try to check what you suggested tomorrow (i have Firebug installed but do not know how to use it yet, i am a nub).Also, I now think I'd better find a way to dynamically pass a "visible" css to this option with PHP in order to have it work with desabled JS?
Ted
there's not much to basic use of firebug (I didn't dig beyond the console and the network traffic monitor [Console and Net tabs]).yes, if you want to have it working same with or without javascript, you should setup the initial state without javascript. like, change `#me` to `.open`, have the rest be collapsed with css.
just somebody
A: 

Ok, the CSS part was easy. It does not use any "visibility" values, instead it changes a box position from "top:-999em" (to hide) to "top:2.5em" (to display). I created a separate class for my , which is just a copy from Superfish "displayable" boxes:

ul.open {
left: 0;
top: 2.5em;
z-index: 99;
}

Now it works if JS is disabled but when JS is enabled all options get collapsed anyway. Here is just one of the many variants i tried this time:

    onInit: function(){$('ul.open').addClass('ul.open');}

and it has no effect at all, as if this class does not exists.

If I try:

    onInit: function(){$('ul.open').html('hello');}

the word 'hello' appears on mouseover instead of submenu - but on mouseover, not "onInit".

Ted