JQuery: multiple switch statements cancelling eachother out -
having trouble more 1 switch statement @ time:
$(document).ready(function(){ $('#menu').children('span').click(function(){ whichsub = $(this).attr('id'); switch (whichsub) { case 'menu1': $('#submenu').load('menus/submenu1.html'); break; case 'menu2': $('#submenu').load('menus/submenu2.html'); break; }; if ( $('#submenu').css('left') !== '150px' ) {$('#submenu').animate({left: '150px'}, 300);} }); $('#submenu').children('span').click(function(){ var whichcon = $(this).attr('id'); switch (whichcon) { case 'submenu1': $('#demopanel').load('content/profile.html'); break; case 'submenu2': $('#demopanel').load('content/portfolio.html'); break; }; if ( $('#demopanel').css('marginleft') !== '300px' ) {$('#demopanel').animate({marginleft: '300px'}, 1000);} }); });
the top switch changes submenu , conditionally slides out, bottom changes content ("#demopanel"). each works on it's own, when have both enabled, second fails work -- acts if script has stopped since alert placed after $('#submenu').children('span').click(function(){
returns nothing.
any ideas might going wrong? need unbind something?
thanks.
delegate submenu click since looks loading dynamic content there using on
..
$('#submenu').on('click','span',function(){ ... })
link read more on delegated events
Comments
Post a Comment