jQuery events .live() wierdness -


i have page toolbar menu @ bottom. have function checks display property of block contains menu items , sets "none" if it's "block" or sets "block" if it's "none".

i'm using jquery bind event object. want use live() method because may dynamically add items toolbar , want event automatically attached new menu elements.

the problem i'm experiencing when bind event element live(), css display property of element i'm checking "none". so, menu never closes.

if use bind() instead of live(), works expect to.

what's causing strange behavior live()?

the demo page reproducing problem http://www.ghodmode.com/tbdemo

thank you.

-- ghodmode

because callbacks bound using .live() executed through event delegation, handlers between target of .live() , document called. looking @ code can see self.hide_menu bound body element. when event bubbles target has class .j_has_menu, click handler on body (self.hide_menu) executed causing menu close. self.hide_menu not return false, event continuse bubbling until reaches document root , calls function expected self.show_menu. means when menu open , click it, self.hide_menu run first , self.show_menu run right after menu perpetually open.

$(document).ready(function () {     var self = new toolbar();     $(".j_has_submenu").live("mouseover", self.show_submenu);     $(".j_has_submenu .j_submenu").live("mouseout", self.delay_hide);     $(".j_has_menu").live("click", self.show_menu);     $('.j_toolbar').siblings().add('body').click(self.hide_menu); // <-- culprit }); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -