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,
e.preventDefault
will prevent to click of button as it is its default behavior.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.