Make this jQuery code a little more dynamic -
jquery(document).ready(function ($) { if (window.location.href.indexof("seniors") > -1) { var $ul_senior = $('<ul class="sub-menu-jquery"></ul>'); $("#menu-item-630").append($ul_senior); $("#menu-carecenter-seniors-menu li").each(function () { var $li = $(this); $($li).clone().appendto(".sub-menu-jquery"); }); }; if (window.location.href.indexof("medical") > -1) { var $ul_medical = $('<ul class="sub-menu-jquery"></ul>'); $("#menu-item-636").append($ul_medical); $("#menu-carecenter-medical-menu li").each(function () { var $li = $(this); $($li).clone().appendto(".sub-menu-jquery"); }); }; if (window.location.href.indexof("foundation") > -1) { var $ul_foundation = $('<ul class="sub-menu-jquery"></ul>'); $("#menu-item-635").append($ul_foundation); $("#menu-carecenter-foundation-menu li").each(function () { var $li = $(this); $($li).clone().appendto(".sub-menu-jquery"); }); }; });
what code clones links sidebar wordpress site , adds them main-nav depending on section of site you're in.
the more code, more realize make more dynamic extracting 'seniors' or 'medical' or 'foundation' #id sidebar, , adding main-nav based on title of tag (also either 'seniors' or 'medical' or 'foundation'.
this way, wouldn't need use specific #menu-item-xxx , totally dynamic.
pretty sure html() function need used. not sure how.
you extract out common areas of javascript function. maybe this?
addmenuitem("seniors", "630"); addmenuitem("medical", "636"); addmenuitem("foundation", "635"); function addmenuitem(location, item) { if (window.location.href.indexof(location) > -1) { var $ul = $('<ul class="sub-menu-jquery"></ul>'); $("#menu-item-" + item).append($ul); $("#menu-carecenter-" + location + "-menu li").each(function() { var $li = $(this); $($li).clone().appendto(".sub-menu-jquery"); }); };
Comments
Post a Comment