Accessing a div appended to a another div.

Accessing a div appended to a another div.

So im trying to create a simple file menu, so far I have :

  1. $(function() {
  2. //Rolling over menu items.
  3. $('#FileMenu a').hover(function(e) {
  4. //Highlight.
  5. $(this).css({'background-color' : '#0099FF'});
  6. //Get index of the menu were on.
  7. var myMenuindex = $('#FileMenu a').index($(this));
  8. //Now remove any children already there and add a new one.
  9. $('#NewMenu').remove();
  10. $('#mnuItemRemoval').remove();
  11. $('#FileMenu').append(CreateFileItems(myMenuindex));
  12. }, function() {
  13. $(this).css({'background-color' : '#F3F2E7'});
  14. });
  15. });

  16.     function CreateFileItems(selectedMenuIndex)
  17. {
  18. var newMenu = '<div id="NewMenu">'
  19. newMenu += '<ul>'
  20. switch(selectedMenuIndex)
  21. {
  22. case 0:
  23. newMenu += '<li><a href="#">File Menu Item 1</a></li>'
  24. newMenu += '<li>File Menu Item 2</li>'
  25. newMenu += '<li>File Menu Item 3</li>'
  26. newMenu += '<li>File Menu Item 4</li>'
  27. newMenu += '<li>File Menu Item 5</li>'
  28. break;
  29. }
  30. newMenu += '</ul>'
  31. newMenu += '</div>'
  32. //This is a tinybox use to remove this list if the user mouses over it.
  33. newMenu += '<div id="mnuItemRemoval"><a href="#">blah blah blah</a></div>'
  34. return newMenu
  35. }
This all works fine, but as soon as i try to do anything to the new menu div using the $('#NewMenu') selector I can't do anything, no events are working at all for it.