开发者

jQuery dynamically added class does not fire

开发者 https://www.devze.com 2023-01-05 04:18 出处:网络
<a href=\"#\" class=\'gbutton yen_form\' rel=\"overlay-box1\">Next</a> $(\'yen_form\').click(function(){
<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

精彩评论

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