I made a system in Codeigniter that does real-time search. In my search, I send the parameters via Ajax to the controller and I make the query.
I put all HTML for a view. Then I get all the HTML of that view through ajax and feed my page replacing the current content with the new one. I did a 1 minute video showing the error:
The error is that the function that I did show / hide content (by clicking on the image) works before Ajax but does not work after Ajax merges with the current content and feeds the div with content.
Function that stops working
$('a[href^="#"]').bind("click", function(event){
event.preventDefault();
var the_id = $(this).attr("href");
$(".detalhes").addClass('hide');
$("div"+the_id+"").parent(".detalhes").removeClass('hide');
$(".theblog ").removeClass("hide");
$(this).parents(".theblog").addClass("hide");
$('html, body').animate({ scrollTop:$(the_id).offset().top-25}, 'slow');
});
I was studying about elements that do not exist and delegate these days and I think there's something to be said about this, can anyone help me solve it. I think I have to change this function so it works on the elements that exist and what will exist.
Well, that's it.