Button alert function not working when loaded with ajax
I have a search form in my page1.php file, which is targeted to page2.php, which displays results. I have a button in my page2.php, which on click, alerts "hi", like;
- $(document).ready(function() {
- $('#alertbtn').click(function(){
- alert("hi");
- });
- });
This works fine when page2.php is loaded separately, without using page1.php's search form. When I search using page1.php's form, and when page2.php appears, the alert function is not working. How can I fix this?