javascript - Delete a DOM element and its associated jquery plugin and data -


  1. first, i'm using jquery plugin on element, lets $('#myelement').useplugin();.

  2. second, want destroy original element , plugin variables etc may still exist in js.

  3. third, create new #myelement , redo $('#myelement').useplugin();.

i'm having trouble step #2. when $('#myelement').remove(), there residual strange behavior when recreate element , instantiate plugin.

fyi: plugin i'm having trouble with: http://mindmup.github.io/editable-table/. if create table, make editable, works fine.

but if delete table, recreate table, make editable, strange behavior fields editable, when hit "enter", value not save , error uncaught typeerror: cannot read property 'trigger' of undefined.

i modify line in plugin:

https://github.com/mindmup/editable-table/blob/master/mindmup-editabletable.js#l115

to:

    $(window).on('resize.mindmup', function () { 

now, when want remove event, remove namespace.

$(window).off("resize.mindmup"); 

continue removing , re-creating table, use above line remove window resize event before re-initializing plugin.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -