Please don't immediately mark this as a duplicate. I've looked at similar questions but still can't figure this out.
This is what I have currently:
$(document).ready(function(){
for(var i=1;i<2;i++)
{
$("#MenuBarButton"+i).mouseover(function(){
$("#ldheMenuBarLayer"+i).stop().animate({height:'66px'},{queue:false, duration:600, easing: 'easeOutBounce'})
});
$("#MenuBarButton"+i).mouseout(function(){
$("#ldheMenuBarLayer"+i).stop().animate({height:'41px'},{queue:false, duration:600, easing: 'easeOutBounce'})
});
}
});
That doesn't work. Nothing happens and nothing appears in the console. But if I directly replace the i with a 1 in each of the $ function things it works.
I'm not new to programming but I'm new to JavaScript, so am I doing something obviously wrong? Thanks!
EDIT: When I say I replace the i with a 1, that's because the IDs are MenuBarButton1 and ldheMenuBarLayer1.
ito a string:.. +String(i). 2. There is no need for a loop here:for (var i=1;i<2;i++)will only "loop" once, withi=1.+expression with a string.$('[id^="MenuBarButton"]')to select all elements with an id attribute starting with "MenuBarButton", so you wouldn't need that loop at all.