I do not have much experience at all with Jquery and am having trouble writing a proper callback function so that a separate javascript function executes after having loaded html content through an ajax .load() call.
The following code loads the external html content
$('#myID').find('a').on('click', function(){
e.preventDefault();
var $desc = $('#insert');
switch($(this).attr('href')) {
case 'content1.html' :
$desc.load('fragments/content1.html');
break;
case 'content2.html' :
$desc.load('fragments/content2.html');
break;
}
});
The following code must then be executed on the html loaded by the previous function
var panelWidth = 0;
var startPanel = 1;
window.panelWidth = $('.sp').width();
$('.panel_container .hiw_panel').each(function(index){
$(this).css({'width':window.panelWidth+'px','left':(index*window.panelWidth)});
$('.sp .panels').css('width',(index+1)*window.panelWidth+'px');
});
$('.switcher span').each(function(){
$(this).on('click', function(){
changePanels( $(this).index() );
});
});
function changePanels(newIndex){
var newPanelPosition = ( window.panelWidth * newIndex ) * -1;
$('.switcher span').removeClass('selected');
}
I've deleted out excess content to make it as concise as possible. All I need to know is how to execute part II after part I. Thanks for your help!