Hi @toolman, are you loading the nav bar yourself or is this done by some 3rd party code? Could you provide a link to the page or a fiddle or something that demonstrates the problem?
Yes but how are you actually loading the content? Using a timeout is definitely not a good solution as it may still break if you have a bad network connection and the request takes longer than your timeout. So you should use a load callback; e.g. if you’re using jQuery’s load() method:
$('.mega-menu').load('mega-menu.html', function () {
// Init stuff once the content got loaded
})
If you are using another library for this, you’ll have to check the docs if it provides a similar way to callback on load. If you don’t have access to the loading mechanism at all, you might use a mutation observer to check when the menu got populated:
new MutationObserver(function (mutations, observer) {
observer.disconnect()
// Init stuff once any nodes got appended to the .mega-menu
}).observe(
document.querySelector('.mega-menu'),
{ childList: true }
)
(The former approach is certainly preferable, but I know there are situations where there just isn’t any way to directly hook into the internal workings of a CMS…)
Those snippets were not supposed to be working out of the box; as I don’t know your markup or how the menu is getting loaded, I can only give you examples for some possible approaches. Of course, you’ll have to adjust the implementation to your actual page.
If it is not loaded with AJAX, then there may indeed be a simpler approach. Maybe you just have to wait until knockout completes rendering… I never worked with knockout though. Do you see something template-like getting loaded in the network panel of the browser dev tools?