javascript - Jquery Live function is not working when used with keyup -
i use loaddata() function data php script , use function search database. works fine, when click on search result, it's not loading data. here jquery functions using,
//gets data function loaddata(id) { loading_show(); $.ajax({ url: "load_data.php", type: "post", data: "id="+id, success: function(data){ loading_hide(); $("#container_wrap_metro").html(data); }, error:function(){ alert("failure"); $("#container_wrap_metro").html('unable process request!'); } }); } //search $(function(){ $("#result").keyup(function(){ var q = $(this).val(); $.get("results.php?q="+q, function(data){ if(q){ $(".side_container").html(data); } else { $(".side_container").html(""); } }); }); $('#b').live('click',function(){ var page = $(this).attr('p'); loaddata(page); }); });
the answer is:
$(document).on('click','#b',function(){...}); //live equivalent but better use closest static container:
$('#container_wrap_metro').on('click','#b',function(){...});
Comments
Post a Comment