function addSlipMenu () { var loggedas = $('#current_user_li:first'); var sub_menu = $('#user_sub_menu'); loggedas.mouseenter(function(event) { sub_menu.show(); }); sub_menu.mouseleave(function(event) { sub_menu.hide(); }); } function addProjectSlipMenu () { var loggedas = $('#my_projects_li'); var project_sub_menu = $('#my_projects_ul'); var course_sub_menu = $('#my_courses_ul'); loggedas.mouseenter(function(event) { course_sub_menu.hide(); project_sub_menu.show(); }); loggedas.mouseleave(function(event) { project_sub_menu.hide(); }); } function addCourseSlipMenu () { var loggedas = $('#my_courses_li'); var project_sub_menu = $('#my_projects_ul'); var course_sub_menu = $('#my_courses_ul'); loggedas.mouseenter(function(event) { project_sub_menu.hide(); course_sub_menu.show(); }); loggedas.mouseleave(function(event) { course_sub_menu.hide(); }); } $(document).ready(function () { addSlipMenu(); addProjectSlipMenu (); addCourseSlipMenu(); });