Hello, I made some changes to the script:
(function($){ var contains = document.compareDocumentPosition ? function(a, b){ return a.compareDocumentPosition(b) & 16; } : function(a, b){ return a !== b && (a.contains ? a.contains(b) : true); }, oldLive = $.fn.live, oldDie = $.fn.die; function createEnterLeaveFn(fn, type){ return jQuery.event.proxy(fn, function(e) { if( this !== e.relatedTarget && !contains(this, e.relatedTarget) ) { e.type = type; fn.apply(this, arguments); } }); } function createBubbleFn(fn, type){ return jQuery.event.proxy(fn, function(e) { var parent = this.parentNode; fn.apply(this, arguments); if( parent ){ e.type = type; $(parent).trigger(e); } }); } var enterLeaveTypes = { mouseenter: 'mouseover', mouseleave: 'mouseout' }; $.fn.live = function(types, fn, bubble){ var that = this; $.each(types.split(' '), function(i, type){ var proxy = fn; if(bubble){ proxy = createBubbleFn(proxy, enterLeaveTypes[type] || type); } if(enterLeaveTypes[type]){ proxy = createEnterLeaveFn(proxy, type); type = enterLeaveTypes[type]; } oldLive.call(that, type, proxy); }); }; $.fn.die = function(type, fn){ if(/mouseenter|mouseleave/.test(t.type)){ if(type == 'mouseenter'){ type = 'mouseover'; } else { type = 'mouseout'; } } oldDie.call(this, type, fn); }; })(jQuery); Now You can enable bubbling, too. Example: var add = function(){ $(this).addClass('over'); }, remove = function(){ $(this).removeClass('over'); } ; $('ul.nav').each(function(){ //no bubble $('> li', this) .live('mouseenter', add) .live('mouseleave', remove); //bubbles $('li li', this) .live('mouseenter', add, true) .live('mouseleave', remove, true); }); regards alex On 20 Apr., 16:23, Walther <waltherl...@gmail.com> wrote: > Thank you! > > I'll have a go when I get home later today and let you know how it > works out. At the very least you've given me a very big starting > block, and perhaps this will end up in the jQuery core! > > On Apr 18, 2:34 am, alexander farkas <i...@corrupt-system.de> wrote: > > > You can try the following code for this (only testet with firefox). > > > (function($){ > > var contains = document.compareDocumentPosition ? function(a, b){ > > return a.compareDocumentPosition(b) & 16; > > } : function(a, b){ > > return a !== b && (a.contains ? a.contains(b) : true); > > }, > > oldLive = $.fn.live, > > oldDie = $.fn.die; > > > function createEnterOutFn(fn){ > > return jQuery.event.proxy(fn, function(e) { > > > if( contains(e.relatedTarget, this) ){ > > e.type = (e.type == 'mouseover') ? > > 'mouseenter' : 'mouseleave'; > > //console.log('e') > > fn.apply(this, arguments); > > } > > }); > > } > > > $.fn.live = function(type, fn){ > > if(/mouseenter|mouseleave/.test(type)){ > > console.log('d') > > fn = createEnterOutFn(fn); > > if(type == 'mouseenter'){ > > type = 'mouseover'; > > } else { > > type = 'mouseout'; > > } > > } > > > oldLive.call(this, type, fn); > > }; > > > $.fn.die = function(type, fn){ > > if(/mouseenter|mouseleave/.test(t.type)){ > > if(type == 'mouseenter'){ > > type = 'mouseover'; > > } else { > > type = 'mouseout'; > > } > > } > > oldDie.call(this, type, fn); > > }; > > > })(jQuery); > > > you can use it like the normal live/die-methods: > > > $('a').live('mouseenter', function(e){ > > console.log(e.type)}); > > > $('a').live('mouseleave', function(e){ > > console.log(e.type) > > > }); > > > but i would call it a plugin: > > > On 11 Apr., 21:36, Walther <waltherl...@gmail.com> wrote: > > > > I am looking for a way to simulate the actions of the hover (or > > > mouseenter/mouseleave) whilst using the live method of binding (The > > > items are dynamic). > > > > Is there a way to do this or will I need to use the 'old fashioned' > > > method of unbinding and rebinding? I do not want to use a plugin.