Update, answer found. Thanks @charlietfl for pointing me in right direction.
By implementing the following I caught the updated tags
<script>
$("div#ItemInfo").on("click", "span.itemclass", function() {
$('#timestamp').text($.now());
});
</script>
Original question: I need some advice on how to get Jquery access to tags updated by php.
This is the code on main page
<!-- Native text with span. => Handled with native script-->
<p> <span>Clickable</span> <span>text</span></p>
<div id="timestamp"></div>
<!-- Content updated from data.php is put here. => Span in this content is NOT handled by native script -->
<div id='ItemInfo'></div>
<script>
$("span").click(function(){
$('#timestamp').text($.now());
$('#ItemInfo').load('data.php?iid=4');
});
</script>
As you see I update content within "ItemInfo" with content from another php page. The (span) tags within this code doesn't seem to be reachable from the native script, so I have to implement another script within the php code, which makes everything much more difficult, especially in regards of escaping and formatting.
echo "<script> $(document).ready(function(){ $(\"span\").click(function(){ var iid = $(this).attr(\"id\"); $(\"#ItemInfo\").load(\"data.php?iid=\" + iid); }); }); </script>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
echo "<span id={$IID}>{$ITEM}</span><br />";
}
Basically I'd appreciate a way to handle the updates from the same script on the main page.
What is the best way to keep a Jquery script updated with all the elements on the page?
I don't know if this is best handled within Jquery or PHP but appreciate all tips on how to do this in best possible manner.