ajax - Why some time jquery click event fails? -
my page divided 2 parts vertically
.left part
menu section. clicking on menu brings proper data related menu in right part
of page. doing using ajax call
, div on right part
refreshed. using jquery click event .. say:
$("#left_part").click(function() { // ajax call here });
now have more jquery action
on right part
. (say show hide div work on click event.
) when new div reloads
on right part click event on right part
not working. when bind click event
works.
say:
$("#some_right_part").click(function() {/ hide show here )}; not working $("#some_right_part").bind('click', function(event){ // hide show here )}; works fine
important: when on fresh page
(no ajax call yet bring right part) $("#some_right_part").click(function() {/ hide show here )}; works fine.
but know is: $().click(function)
calls $().bind('click',function)
so, reason behind this? or perfect way solve such problem
thanks
when assign click event via $().click
when page loads, click event bound matching elements. however, when ajax call , recieve new markup - new elements not bound click event because did not exist when first called $().click
.
there way click event bound elements , future elements may created. must use live method so:
$('#elements').live('click', function() { // logic });
Comments
Post a Comment