Accessing a div appended to a another div.
So im trying to create a simple file menu, so far I have :
- $(function() {
- //Rolling over menu items.
- $('#FileMenu a').hover(function(e) {
- //Highlight.
- $(this).css({'background-color' : '#0099FF'});
- //Get index of the menu were on.
- var myMenuindex = $('#FileMenu a').index($(this));
- //Now remove any children already there and add a new one.
- $('#NewMenu').remove();
- $('#mnuItemRemoval').remove();
- $('#FileMenu').append(CreateFileItems(myMenuindex));
- }, function() {
- $(this).css({'background-color' : '#F3F2E7'});
- });
- });
- function CreateFileItems(selectedMenuIndex)
- {
- var newMenu = '<div id="NewMenu">'
- newMenu += '<ul>'
- switch(selectedMenuIndex)
- {
- case 0:
- newMenu += '<li><a href="#">File Menu Item 1</a></li>'
- newMenu += '<li>File Menu Item 2</li>'
- newMenu += '<li>File Menu Item 3</li>'
- newMenu += '<li>File Menu Item 4</li>'
- newMenu += '<li>File Menu Item 5</li>'
-
- break;
-
- }
- newMenu += '</ul>'
- newMenu += '</div>'
-
- //This is a tinybox use to remove this list if the user mouses over it.
- newMenu += '<div id="mnuItemRemoval"><a href="#">blah blah blah</a></div>'
-
- return newMenu
- }
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.