执行Ajax函数后,按钮单击不起作用[重复]

This question is an exact duplicate of:

I have a readmore button which is generated with Ajax and now I am using below code to execute a click event from this button, but nothing happens.

The button when clicked should unhide a div which is also dynamic and generated with Ajax. So this is all dynamic content I am dealing any ideas please. Thanks.

jQuery:

jQuery(document).on('click', '#readmore', function(e){
    e.preventDefault();
    alert("you clicked the button");
    jQuery("#bodytext").css("display", "block");
});
</div>

You have 2 options to make it work,

  1. convert your button to hyperlink as e.preventDefault will prevent to click of button as it is its default behavior.
  2. Remove the e.preventDefault() from your code.

Also make sure your have included any latest version of jquery. And write your code in $.ready() like,

$(function(){
    // your code here
});

Now, try to use any one option from the above.