javascript - OnClick interaction with .load(ed) page not working -
i'm in process of loading view different info panels using jquery's .load() function. however, of content in loaded element i'd interact (using .on('click')) doesn't seem responding accordingly. can have click actions on dynamically loaded content? if not, what's best work around? #updatejson lives within viewjson.php file.
$().ready(function() { $("#viewlatestjson").load("viewjson.php"); $("#viewlivedatafeeds").load("viewfeed.php"); $('#updatejson').on('click', function(e){ e.preventdefault(); $("#alertpanel").removeclass( "success warning info alert secondary" ); $("#alertpanel").addclass( "secondary" ); $("#alertmessage").html( "<img src=\"icons/alert-loader.gif\"> updating local json conversion, please wait..." ); $("#alertpanel").fadein(300); $.ajax({ url: 'downloadjson.php', type: 'post', data: {'update': 'yes'}, success: function(data, status) { if(data == "complete") { settimeout(function(){ $("#alertpanel").removeclass( "success warning info alert secondary" ); $("#alertpanel").addclass( "success" ); $("#alertmessage").html( "json conversion complete. have latest pull." ); }, 3000); } else if(data == "notime") { settimeout(function(){ $("#alertpanel").removeclass( "success warning info alert secondary" ); $("#alertpanel").addclass( "info" ); $("#alertmessage").html( "cannot update: allowed update every 20 minutes." ); }, 3000); } } }); });});
try passing function adds click handler callback load
function, know element there before try , apply click handler it.
$("#viewlivedatafeeds").load("viewjson.php",function(){ $('#updatejson').on('click', function(e){ e.preventdefault(); /* . . . */ } });
Comments
Post a Comment