Friday, 23 August 2013

Dynamic click events not attaching. .bind()

Dynamic click events not attaching. .bind()

Theres probably a better way of doing this, but I'm trying to remove and
then attach click events to the following elements.
$("#clickDiv2").bind('click',showAction2);
$("#clickDiv3").bind('click',showAction3);
$("#clickDiv4").bind('click',showAction4);
The function works fine, $("#clickDiv").bind('click',showAction); works
and it's at the end of the function, but the three I mentioned above do
not. Could anyone explain why this might be?
$("#clickDiv").click(function showAction(){
$("#obj1tbl").show();
$("#obj1tbl").animate({left: "100"});
$(".goActive").addClass('glow');
$("#clickDiv2").unbind('click');
$("#clickDiv3").unbind('click');
$("#clickDiv4").unbind('click');
$("#clickDiv").bind('click', function gogo(){
$("#obj1tbl").animate({left: "999"});
$("#obj1tbl").hide();
$(".goActive").removeClass('glow');
$("#clickDiv").unbind('click');
$(".dataTableClass").css("opacity", "1");
$("#clickDiv2").bind('click',showAction2); // DOES NOT WORK
$("#clickDiv3").bind('click',showAction3); // DOES NOT WORK
$("#clickDiv4").bind('click',showAction4); // DOES NOT WORK
$("#clickDiv").bind('click',showAction); //WORKS!!
});
});
Cheers!

No comments:

Post a Comment