Since you're rewriting the content into the #maintab
, all events handlers you defined once at DOMready
- for nodes inside it - can't work if a new request change its content (even if the new elements injected inside that container are the same: the handlers defined were attached to nodes that no longer exist).
So you need to use event delegation and capture your events on the #maintab
(or on a parent element)
E.g. your example becomes
$('#maintab').on('mousedown', '#showdivitem1', function(){
$('#item1').show();
});
You're setting the handler to #maintab
(that node is not removed at every ajax request) and this captures the propagation of a mousedown
event in #showdivitem1
element