I have a very weird question today. I am building a huge application with jQuery, Ajax and PHP.
Basically I'm loading the contents of a div with PHP once the page loads.
<div id="samplediv">
<a href="#" id="click1">Test1</a>
<a href="#" id="click2">Test2</a>
<a href="#" id="click3">Test3</a>
</div>
When someone clicks on these, an alert should come up, like this:
$("#click1").on("click", function(){
alert(1);
});
However if the client clicks on
<a href="#" id="click_here">Click</a>
a jQuery function is triggered like the following:
$("#click_here").on("click", function(){
fillDiv();
});
fillDiv()
function is basically calls and ajax function and fills the div with the result, the PHP page returns.
This is basically the exact same as the top div. Php returns the followig:
<a href="#" id="click1">Test1</a>
<a href="#" id="click2">Test2</a>
<a href="#" id="click3">Test3</a>
And the fillDiv()
function places this into the samplediv
. I've checked the HTML of the 2 result is the Exact same!
Problem:
When the items are loaded back from the Ajax function, with thee exact same html, IF I click on any of the Test1, Test2, Test3 links, I got back nothing actually. No alert, nothing. Not even an error message.
What could be the issue, which I didn't encounter?