I'm trying to add a custom java-script file into Magento by placing the following into local.xml
<action method="addJs"><script>nav/navigation.js</script></action>
navigation.js
$sub = $('div.col-md-2.right-content');
$('div.col-md-10').on({
mouseenter: function() {
var i = $(this).index();
$sub.addClass('li-'+i);
}, mouseleave: function() {
$sub.removeClass().addClass('col-md-2.right-content');
}
})
style.css
li.level2.nav-2-1-1.first{
background-color: green;
}
li.level2.nav-2-1-2.last{
background-color: red;
}
The purpose of this is that whenever a user hover over a link inside my submenu, the right-content will change accordingly. The problem is that my navigation.js file is targeting objects that does not exist until after the menu is loaded. These being 'div.col-md-2.right-content' and 'div.col-md-10'.
Is there a way to load the javascript after the menu has loaded? Or is there another way to accomplish this? Or am I just approaching this completely wrong.