Error using appendTo

Error using appendTo

I'm trying to use appendTo with some PHP so I can move a ul to the bottom.

Here is my code:

  1. <?php 
  2. $currentPath = $this->getCurrentPath();
  3. $currentCategory = Mage::registry('current_category');
  4. ?>
  5. <script type="text/Javascript">
  6. jQuery(document).ready(function(){
  7. $(".childnav").appendTo(".catalognav");
  8. });
  9. </script>
  10. <ul class="catalognav">

  11.     <?php foreach ($this->getCategories() as $category): ?>
  12. <li>
  13.    <a<?php if ($currentCategory->getId() == $category->getId()): ?> class="selected" <?php endif ?> href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?></a>
  14. </li>
  15. <li><span>/</span></li>
  16. <?php if ($currentCategory->getId() == $category->getId() || in_array($category->getId(), $currentPath)): ?>
  17. <ul class="childnav">
  18.    <?php foreach ($this->getSubcategories($category->getId()) as $subcategory): ?>
  19.        <li><a<?php if ($currentCategory->getId() == $subcategory->getId()): ?> class="selected" <?php endif ?> href="<?php echo $subcategory->getUrl() ?>"><?php echo $subcategory->getName() ?></a></li>
  20.        <li><span>/</span></li>
  21.    <?php endforeach ?>
  22. </ul>
  23. <?php endif ?>
  24.     <?php endforeach ?>
  25. </ul>
When I run the website basically nothing happens. The code should work as I've tried it without all the PHP.

Here is the error:
  1. Uncaught TypeError: Cannot call method 'appendTo' of null
How can I fix this?

Thank you for any help in advanced!