javascript - Event not attached -


i have function dynamically creates element , attaches click event new element.

in current state of app, function called 5 times: 4 first created elements, works fine, 5th 1 has no event attached!

i insist: i'm not merely saying click doesn't work: using $._data(myelemn,'events') in console, object { click=[1]} returned 4 working elements, "undefined" last one.

here code. don't think problem lies: since works other elements, seems difference should come particular context of 5th element. question rather: can imagine particular conditions may cause , event not attached (obviously,without error message).

var createddt= function(element) { /*     --------- creates drop-down toggle button embedded element. */   $(element).css({position:'relative'}) // (relative: since ddt pos absolute)   .append(     $('<span \/>').addclass(ddt)     .css({display:'none',})     .append($('<span \/>'))     // when click, toggle submenu:     .click(function(event) {       // hide or show current %submenu:       var submenu=$(event.target).closest('li').find(jqsubmenu);       submenu.toggleclass(open);       // hide other %open %submenu:       $(jqopen).not(submenu).removeclass(open);       settimeout(livewidthdisplay,_params.csstimeout); // adjust lwd's position       return false; // avoid following link, if embedded in <a>     })   ); } 

thanks in advance comment.

[edit] said, issue resides outside of function. emphasize it, in app tried replacing code following:

var createddt= function(element) { /*     --------- creates drop-down toggle button embedded element. */   $(element).css({position:'relative'}) // (relative: since ddt pos absolute)   .append(     $('<span \/>').addclass(ddt)     .css({display:'none',})     .append($('<span \/>'))     // when click, toggle submenu:     .click(function(event) {       alert(event.target.id);     })   ); } 

then result unchanged: "$._data(myelem,'events')" returns "undefied".

unfortunately, can't realistically add significative context jsfiddle, since huge app.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -