I want to bind an element with a function via live() method.
The function excecutes just fine only for the first time.
I think that I have to unbind this element from any events and rebound the same function but I don’t know how to do it!
Here is the code:
var temp = function() {
var htmlEx = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
$('#template_loading').fadeIn();
$('#template_loading').queue(function() {
$('#tp_prev').html(htmlEx);
$('#template_container').removeClass("cur_temp");
$('#template_container').addClass("cur_prev");
$('#template_container').animate({"margin-left" : "0"}, 400, 'easeOutExpo');
$('#template_container').queue(function() {
$('#template_loading').fadeOut();
$('#tp_cur').empty();
$('#template_container').removeClass("cur_prev");
$('#template_container').addClass("cur_temp");
$('#tp_prev').empty();
$('#tp_cur').html(htmlEx);
$('#tp_cur').queue(function() {
$('#prev.pers_arrow').die();
$('#prev.pers_arrow').live("click", temp);
$(this).dequeue();
});
$(this).dequeue();
});
$(this).dequeue();
});
};
$('#prev.pers_arrow').live("click", temp);
the first: NEVER, EVER, EVER do like that.
You have to cache your data and don’t jump all time into the dom!!!
second:
in my opinion live is deprecated -so you can use on and off
try that: