I have an empty div, like this:
<div id="my-content"></div>
Then i have some jQuery, something like this:
/**IGNORE THIS**/
function makeButton(){
$('#my-content').html('<input type="button" value="Say hey" id="my-button" />');
}
So far, so good. Then i have this js:
$(document).ready(function(){
makeButton();
});
Works perfect, but, when i after this makes a trigger for this button, so it looks like the following, it does not respond to the button id...
$(document).ready(function(){
makeButton();
$('#my-button').click(function(){
alert('Hello!');
});
});
I can of course add <script>$(document).ready... blah... alert('Hello');</script>
into the .html() in the makeButton function, but i guess that's not the real way to do it.
How will i tell the JS to start listen for clicks AFTER makeButton() is ready and has added the button?
EDIT: Ok, that works. Sorry. The actual case is not really like the above, but similar.
the makeButton() is actually another function that gets data by ajax, so makeButton is more like this:
makeButton(){
$.ajax({
type: 'POST',
url: 'ajax_images.php',
data: {pageNr: pageNr},
success:function(response) {
//Loops the json and does something like this:
var HTML = '<div id="thumbnail">;
HTML += 'Response Stuff'
HTML += '</div>';
$('#my-content').html(HTML);
}
});
}
Sorry for beeing confusing.