I need to add a class to a div based on how cookies are set. I have something like :
var tagPanelState = $.cookie('tagPanel');
var catPanelState = $.cookie('catPanel');
if ((tagPanelState == "expanded") && (catPanelState == "expanded" ))
{
$('.tagTable').addClass( 'catBumpTwo' );
};
The problem is $.tagTable is loaded into the dom with ajax via :
var loadHistory = '<?php bloginfo( 'url' ); ?>/tag/'+ tagPanelHistory + ' .tagTable';
$('.tagTable').detach();
$('#tagThumbs').load( loadHistory );
$('.tagTable').appendTo($('#ajaxTable'));
$('.tagTable').addClass( 'catBumpTwo' );
In neither case is catBumpTwo added unless I put an alert or breakpoints before it, then it is added. So I guess I need to use something like .on but the only way I have used that (or .live or .delegate) are with an event so I am not sure how I would addclass for this example.
If you want to do something after a call to load() completes, pass a callback to the load() function. Here’s an example, using variable names from your code: