开发者

jQuery dynamically added class does not fire

<a href="#" class='gbutton yen_form' rel="overlay-box1">Next</a>

$('yen_form').click(function(){
  //some validations done here
  $(this).addClass('overlay');
});

$('overlay').click(function(){
  //overlay appears
})

First function fires correctly but the second 'overlay' class function does not fired at all. If I adde开发者_JAVA技巧d overlay to the anchor it works properly. why???

Can any one solve this or I am doing anything wrong??


Use the live method $(".overlay").live("click", function() { });

NB After adding the class to the anchor, live event will fire immediately. Can't you just show the overlay rather than adding a class? Use the code below

$('.yen_form').click(function(){
  //some validations done here
  $(this).addClass('overlay');
});

$('.overlay').live("click", function(){
  //overlay appears
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜