开发者

jQuery .live() only works one time

开发者 https://www.devze.com 2023-02-10 22:27 出处:网络
I have a simple jQuery AJAX code which generates XHTML code: $(\"a.close\").live(\"click\", function( e ){

I have a simple jQuery AJAX code which generates XHTML code:

$("a.close").live("click", function( e ){
  开发者_StackOverflow  e.preventDefault();      
    $( '#info' ).fadeOut( 'slow' );
});

This code works great once. My div closes and everything is fine, but if I click on the link that opens up my #info div a second time then I can't close the div. I get no errors in Firebug and I can't solve the problem.


Could you try returning false instead of calling e.preventDefault?


Try the following:

$("#info").fadeOut('slow').remove();

It's possible you're adding multiple '#info' boxes, but not actually removing the old ones - just hiding them.

0

精彩评论

暂无评论...
验证码 换一张
取 消