I am writing a user macro and part of the code is going to target the active page in the page tree (which uses the {pagetree} macro) and apply some simple styling to it.
The code is as follows:
#set ($activePage = "#childrenspan$content.getIdAsString()-0")
<script type="text/javascript">
var AP = '${activePage}';
jQuery(AP).addClass('activePage');
</script>
As you can see it's a mixture of VTL and JS - the VTL sets a variable and passes it to the JS, which is basically the ID for the current page in the page tree.
However, it is running before the page tree has loaded. This means that it's effectively returning nothing. If you run the code in the developer console after the page has finished loading then it works.
So the question is, how can I run some JS after the {pagetree} macro has finished loading?