单击动态创建的链接而不识别单击事件

When you click on a folder a button/link is prepended to the nav section but when i click on the added button it will not work. It does not recognize my click event for some reason..?

quick video of what i am dealing with. https://www.youtube.com/watch?v=NsW1uLbRd9w

I am clueless on why it is not working ahhhh Any help would be awesome, thanks. If you need more code i can send it if needed.

    <script>
      $(function () {
        // When folder is clicked open it
        $('button.<?php echo $row->folderName; ?>').bind('click', function() { 
            $('.open.<?php echo $row->folderName;?>').show();
              // if folder is open then Prepend homebtn button to nav
              var k = $('.open').css('display');
              if(k == 'block') {
                $('.nav').prepend('<a class="gohome">HELLO</a>');
              }
        });
            $('.gohome').live('click', function() {
                $('.open.<?php echo $row->folderName; ?>').hide();
              });

      });
    </script>

To bind to future elements you need to bind the event to a parent that exists at the time that the procedure is executed. As your link as being added to .nav, that's what we can use. I am assuming .nav. exists when this code is run. If not, use $(document).on('click'...

  $('.nav').on('click', '.gohome', function() {
      $('.open.<?php echo $row->folderName; ?>').hide();
  });