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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -