php - Any extra steps required to ensure jQuery functionality on dynamic content fetched by getJSON? -
i have learnt how use jquery's getjson
method php file making queries on mysql database running results through php's json_encode
.
<script> $(document).ready(function() { $(".click_me").click(function(){ $.getjson("http://path/to/file.php",function(results){ $("#container").html(results[0].key-name); }); }); }); </script>
the functionality working except returned data (html) has classes wrapped around content should triggering jquery actions on hover , click etc.
none of functionality working though , wondering if there sort of 'reinitialisation' needs take place on content 'dynamically' generated getjson
method?
the handlers have attached page @ load attached elements present during call. need either 1. attach them again calling teh functions 2. use $.on
suppose added handler
$(".someclass").click(dosomething)
. can call line again , handler reattached class. after ajax call.you can use
$(".someclass").on("click",dosomething)
add event handler. check format of on. not entirely sure of syntax
edit: in response comment
function inittooltipster(){ //move seperate function can call $('.tooltip').tooltipster({ functionbefore: function(origin, continuetooltip){ origin.tooltipster('update', $(origin).text()); continuetooltip(); } }); } $(document).ready(inittooltipster); $(document).ready(function () { $(".click_me").click(function () { $.getjson("http://path/to/file.php", function (results) { $("#container").html(results[0].key - name); inittooltipster();//init here again //or call tooltipster inside context of container $('#container .tooltip').tooltipster({ functionbefore: function(origin, continuetooltip){ origin.tooltipster('update', $(origin).text()); continuetooltip(); } }); }); }); });
Comments
Post a Comment