Don't worry, ajax loadable nodes will have the jstree-open or jstree-closed classes sent in the initial ajax response from the server (see Hierarchy.php). The above code which I just commented on will pick this up, and ensure the appropriate class is set right first time, rather than trying to fix it after the fact.