I am having a very specific problem in JQuery
The code below is used to Show/Hide a div
. The trigger to show/hide the div
will have the same ID as the div, and have classes (as selectors) showTrigger/hideTrigger
respectively.
wireActionPanelv3 = function(panel, fnDoThisOnShow, fnDoThisOnHide) {
var id = $(panel).attr("id");
var showTrigger = $('#' + id + '.showTrigger');
var hideTrigger = $('#' + id + '.hideTrigger');
$(showTrigger).live('click', function(event) {
if (fnDoThisOnShow != null) fnDoThisOnShow();
$(panel).slideDown("fast");
return false;
});
$(hideTrigger).live('click', function(event) {
if (fnDoThisOnHide != null) fnDoThisOnHide();
$(panel).slideUp("fast");
return false;
});
};
This is how I call this function
wireActionPanelv3($('div[id="configure-filter"]'),null, null);
When the page first loads, this works perfectly when the triggers are clicked. Everything fine till now.
There are some actions which refresh the div
in context. Now, when I click on the show/hide trigger, the code enters the click event above, but it does not show me the div back.
When I use bind
instead of live
, and call the initialization again it works. I wanted to use live
as I don't need to bother about the reinitialization again.
What fact am I missing about live
which can explain this behavior to me?