javascript not executing in (with ajax) loaded link
I'm loading page.php into a div with ajax开发者_如何转开发.
page.php contains some javascript and shows when I load the page in a single window. But when I load it into my website it doesn't show the javascript. (I have added some other code to check but only the Javascript is not working)
$('#winkelZELFlink').click( function() {
  alert('U komt nu bij onze webshop.');
  $.get('http://www.weetzelf.nl/?page_id=147', function(winkelLINK) {
    $('.content').html(winkelLINK);
  });
});
Javascript events added to elements before they exist on the page doesn't work. Luckily jQuery can take care of that with the $.fn.live() function, which delegates events for existing items and items that will be added later, after the code is executed.
Your code should look something like this:
$('#winkelZELFlink').live('click', function() {
    alert('U komt nu bij onze webshop.');
    $.get('http://www.weetzelf.nl/?page_id=147', function(winkelLINK) {
        $('.content').html(winkelLINK);
    });
});
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论