ready functions not loading after appending

Discussion in 'jQuery' started by sandstorm140, Apr 26, 2012.

  1. #1
    Greetings,

    I have the following in my head tag:
    
    <script type="text/javascript">
        $(function() {
            $.get('content/menu_items.txt', function(data) {
                var menu_items = data.split('\n');
                 $.each(menu_items, function(key, val){
                     var menu_items_split = val.split(',');
                        $('#header-bg > .inline_links').append('<a href="'+  menu_items_split[1] +'"><li>'+  menu_items_split[0] +'</li></a>');
                 });   
            });   
        });
    </script>
    
    Code (markup):
    I also have a ready function called to add rounded corners to my nav buttons. Everything works fine if I statically add the li tags into the div, but if I use the above code, the corner functions and animations aren't applied. Any idea's why this is?

    If you don't understand, here is the full code and comments to help you better understand
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js"></script>
    <script type="text/javascript" src="js/jquery.corner.js"></script>
    <script type="text/javascript" src="js/default.js"></script>
    
    <script type="text/javascript">
        $(function() {
            $.get('content/menu_items.txt', function(data) {
                var menu_items = data.split('\n');
                 $.each(menu_items, function(key, val){
                     var menu_items_split = val.split(',');
                        $('#header-bg > .inline_links').append('<a href="'+  menu_items_split[1] +'"><li>'+  menu_items_split[0] +'</li></a>');
                 });   
            });   
        });
    </script>
    </head>
    
    <body>
    
    <div id="header-bg">
        <ul class="inline_links">
    
    <li>test</li> //THIS WORKS, ADDS ROUNDED CORNERS AND ANIMATION;
    
        </ul>
    </div>
    
    </body>
    </html>
    
    Code (markup):

     
    sandstorm140, Apr 26, 2012 IP
  2. sandstorm140

    sandstorm140 Peon

    Messages:
    80
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    problem solved. switched .get function to .ajax with async off and works just fine.
     
    sandstorm140, Apr 27, 2012 IP
  3. gotanz

    gotanz Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Always use the .on() function to bind if you use ajax.
    api.jquery.com/on/
     
    gotanz, May 7, 2012 IP