The web isn't being very helpful on this, so here goes: I have the following which works fine:
var $profile = $("#usermenu"), pos, width;
var showProfileMenu = function(){
//get the position of the placeholder element
pos = $(this).offset();
width = $(this).width();
height = $(this).height();
$profile.css({ "left": (pos.left - 5) + "px", "top":(pos.top + height + 11) + "px" }).prependTo("#user").show();
}
var hideProfileMenu = function() {
$profile.hide();
}
$("#user").hover(showProfileMenu, hideProfileMenu);
But now I have a series of these so I want to make the function more generic. So I tried the following, but it isn't working:
var $recordfilter = $("#subfmenu"), pos, width;
function showFilterMenu(menu, id) {
pos = $("#"+id).offset();
width = $("#"+id).width();
height = $("#"+id).height();
menu.css({ "left": (pos.left - 5) + "px", "top":(pos.top + height + 11) + "px" }).prependTo("#"+id).show();
}
function hideFilterMenu(menu) {
menu.hide();
}
$("#recordfilter").hover(showFilterMenu($recordfilter, "recordfilter"), hideFilterMenu($recordfilter));
It isn't even doing anything on the hover event and there aren't any JS errors, so I don't know what I'm doing wrong. Help?